C#:
public class Cat
{
// Auto-implemented properties.
public int Age { get; set; }
public string Name { get; set; }
public Cat()
{
}
public Cat(string name)
{
this.Name = name; //I do not see a field called Name declared
}
}
C#:
Cat cat = new Cat { Age = 10, Name = "Fluffy" };
Cat sameCat = new Cat("Fluffy"){ Age = 10 };
I was just re-visiting some C# material over the Internet and found the code above which is meant to explain the concept of object initialisation.
The above code is confusing me because a parameterized constructor is declared that supposedly meant to set the field "Name".
But I don't see a field "Name" declared anywhere.
I do however see a property "Name" but this is not a field.
Does anyone else agree with what I am saying?