Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How to give a default value to a C# Auto-Property?

NickFNickF USAMember Posts: 132

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?



  • DavidMDavidM USAMember Posts: 342

    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; }
Sign In or Register to comment.