Calling base constructor in C#: how to properly pass parameters?
Hi everyone! I just started learning C# and encountered a problem with class inheritance. I have a base class `Animal` that has a constructor with a parameter:
```csharp
public class Animal
{
public string Name { get; set; }
public Animal(string name)
{
Name = name;
Console.WriteLine($"Animal created: {Name}");
}
}
```
Now I want to create a `Dog` class that inherits from `Animal` and also has its own constructor. I want the base class `Animal` constructor to be called when creating a `Dog` object, but I don't understand how to do it correctly. Here's what I tried to write:
```csharp
public class Dog : Animal
{
public string Breed { get; set; }
public Dog(string name, string breed)
{
// I want to call
No answers yet.
Log in to leave an answer