I have a C# class that looks like this:
public class Animal { public string _name = "Animal"; public string GetGreeting() { if (this._name == "Animal") { return "Hello friend!"; } else { return $"Hello, '{this._name}'"; } } } public class Tiger : Animal { // How do I set "_name" here? } I want to hard-code the _name value in the Tiger class. However, I don't want to force other classes to set the _name value. How do I do that in C#?
public string Name {get;set;}would be a far better ideanew Animal()return? I suppose the base-class shouldn't be instantiable. Better make itabstract.