C# auto property

By admin - Last updated: Tuesday, March 25, 2008 - Save & Share - Leave a Comment

ReSharper is good tool, it taught me the auto property in .NET 3.5 today.

// traditional property declaration
    public class Foo
    {
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private int _age;
        public int Age
        {
            get { return _age; }
        }
    }

    // auto property
    public class FooAuto
    {
        public string Name { get; set; }
        public string Age { get; private set; }
    }



Posted in Random • Tags: Top Of Page

Write a comment


Captcha: 7 − six =