Can someone please let me know what is the best way to set a default value to a C# Auto-Property? Is it [possible using a constructor?
Yes, you can use the constructor to do it.
class Test { public Test() { //do anything before variable assignment //assign initial values Name = "Default Name"; //do anything after variable assignment } public string Name { get; set; } }
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Yes, you can use the constructor to do it.