C# BestPractice: Private var and Public Getter/Setter or Public Var

Posted by Desiny on Stack Overflow See other posts from Stack Overflow or by Desiny
Published on 2011-01-07T20:44:16Z Indexed on 2011/01/07 20:53 UTC
Read the original article Hit count: 140

Filed under:

What are the advantages and differences between the below two coding styles...

public void HelloWorld () {

        private string _hello;

        public string Hello {    
           get
            {
                return _hello;
            }
           set
            {
                _hello = value;
            }
        }
}

or

public void HelloWorld () {

        public string Hello { get; set; }

}

My preference is for short simple code, but interested to hear opinions as I see many developers who insist on the long route.

© Stack Overflow or respective owner

Related posts about c#