O'Reilly logo

WCF 4.0 Multi-tier Services Development with LINQ to Entities by Mike Liu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Automatic properties

In the past, if we wanted to define a class member as a property member, we had to define a private member variable first. For example, for the Product class, we can define a property, ProductName, as follows:

        private string productName;
        public string ProductName
        {
            get { return productName; }
            set { productName = value; }
        }

This may be useful if we need to add some logic inside the get or set methods. But if we don't need to the above format gets tedious, especially if there are many members.

Now, with C# 3.0 and above, the previous property can be simplified into one statement:

public string ProductName { get; set; }

When Visual Studio compiles this statement it will automatically create a private member variable, productName, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required