您的位置:首页 > 编程语言 > C#

Some New in C# 3.0 language

2008-04-11 09:58 399 查看
1 Automatic properties


public string Name ...{ get; set; }

2 Partial Methods ?

3 Object Initializers


TextBox t = new TextBox ...{Text="Hi", Multiline=true, Location = new Point(5,5), Size=new Size(50,100)};

4 Anonymous Types


var o = new ...{SomeField=DateTime.Now, AnotherField=5.6};

5 Extension methods (Should in static class )
  Declare:

  [Extension()]


  public static bool IsAllUppercase(string s) .........{...}
  // OR


  public static bool IsAllUppercase(this string s) .........{...}

  Usage

     string str;
     str.IsAllUppercase();

6 Lambda Expressions

delegate bool SomeDelegate(int i);
private void SomeMethod()


...{


 SomeDelegate sd = delegate(int i)...{return i > 2;} ;
 //Or SomeDelegate sd = i => i > 2;
 YetOneMore(sd);
}
private void YetOneMore(SomeDelegate f)


...{
 bool res = f(5);
 Console.WriteLine(b.ToString());
}

Comes From Top 10 things to know about Visual Studio 2008 and .NET Framework 3.5 by Daniel Moth
PS: The Office 2003 templates in VS2008 attract me :)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息