What is the best way to go in order to get the class name when creating an object?
This is what I've got but need help with syntax as well as what the best practises are.
This is what I've got but need help with syntax as well as what the best practises are.
Class: Animal:
class Animal
{
public string Name { get; set; }
public int Age { get; set; }
public string FavFood { get; set; }
public string TypeOfAnimal {get; set;}; // Can the type name of the current class be set or specified in the property directly? Or is that totally wrong?
Console.WriteLine("TypeOfAnimal + Name );
}
class Cat : Animal:
{
public string AnimalType { get; set; } = "Cat"; // Or should it be set in the inherited class likeso?
}
class Application:
class Application
public void CreateDummyAnimals()
{
Petowner.Pets.Add(new Cat
{
Name = "Missy",
Age = 3,
FavFood = "Mice",
Breed = "Ragdoll",
TypeOfAnimal = // How do I get the name of the Cat object?
Toys = new List<Toy>()
});
}
Last edited: