C#自動實作屬性的基本型與變化型

摘要:C#自動實作屬性的基本型與變化型

基本型:


public double TotalPurchases { get; set; }

資料來源:
Auto-Implemented Properties (C# Programming Guide)
http://msdn.microsoft.com/en-us/library/bb384054.aspx

變化型一:(以private修飾set搭配建構函式傳入參數)


public string Name { get; private set; }

變化型二:(以private修飾set搭配Factory Method Design Pattern)


        public static Contact2 CreateContact(string name, string address)
        {
            return new Contact2(name, address);
        }

資料來源:
How to: Implement a Lightweight Class with Auto-Implemented Properties (C# Programming Guide)
http://msdn.microsoft.com/en-us/library/bb383979.aspx

資料來源:
Exploring the Factory Design Pattern
http://msdn.microsoft.com/en-us/library/ee817667.aspx