Calling base constructor in C#: how to pass parameters from derived class?
Hi everyone! I just started learning C# and ran into a problem with inheritance. I have a base class `Animal` with a constructor that takes a name and age. I want to create a derived class `Dog` that adds a `Breed` property. But I don't understand how to properly call the base class constructor from the `Dog` constructor to pass the name and age.
Here is my code:
```csharp
public class Animal
{
public string Name { get; set; }
public int Age { get; set; }
public Animal(string name, int age)
{
Name = name;
Age = age;
}
}
public class Dog : Animal
{
public string Breed { get; set; }
// This is where I'm stuck - how to call Animal(name, age)?
public Dog(string name, int age, string breed)
No answers yet.
Log in to leave an answer