C# 3.0 初試!!

用左 VS 2008 其實都幾個月, 但因公司目標係 .net 2.0 既關係, 技術始終都仲停留緊係 2.0 度, 近日開始習慣緊 C# 3.0 既 syntax, 有幾個新 feature 係 2.0 platform 都幾好用.

Object initializers
呢個係一個新既 contractor syntax, 可以好方便咁創建同設定 Value. 但如果個 Properties 係 private set; 既話就用唔到啦!!

Customer c1 = new Customer { Name="James" };
Customer c2 = new Customer { Name="Tom" };

Lambda expressions
Lambda 好好用!! 簡單, 快捷!!

string name = "James";
IList<Customer> result = list.FindAll(x => name.Equals(x.Name));

Automatic properties
呢個可以簡化到部份 properties, 但如果有 business logic 既話就唔係太啱用

public decimal UnitPrice
{
    get;
    private set;
}

Tags:

Leave a Reply

You must be logged in to post a comment.