C#4.0 新点汇总

1. Dynamic

 

dynamic contact = new ExpandoObject();
contact.Name = "Patrick Hines";
contact.Phone = "206-555-0144";

2. Covariance and Contravariance

 

IEnumerable<Object> objects = new List<String>();

3. Optional (or Default) Parameters

Method declaration:
public static void SomeMethod(int optional = 0) { }

 

Method calls:
SomeMethod(); // 0 is used in the method.
SomeMethod(10);

 

4. Improved COM Interop

   以前:

 

var excelApp = new Excel.Application();
// . . .
excelApp.get_Range("A1", "B4").AutoFormat(
    Excel.XlRangeAutoFormat.xlRangeAutoFormatTable3,
    Type.Missing, Type.Missing, Type.Missing,
    Type.Missing, Type.Missing, Type.Missing);

现在:

 

excelApp.Range["A1", "B3"].AutoFormat(
    Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic2);

posted @ 2010-04-27 09:31  bndy  阅读(282)  评论(0编辑  收藏  举报