Đang chuẩn bị liên kết để tải về tài liệu:
Lập trình .net 4.0 và visual studio 2010 part 6

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

NET tham số tùy chọn và đặt tên là thực hiện điều này dễ dàng hơn nhiều: betterWay var = WordApplication.Documents.Open (tập tin, chỉ đọc: sự thật, nhìn thấy: đúng); betterWay.Activate (); Các chức năng mới năng động (mà chúng tôi sẽ xem xét ngay) cũng có thể làm cho mã của bạn dễ đọc hơn bằng cách cho phép bạn để suy ra nhiều hoạt động đúc. | CHAPTER 3 LANGUAGE AND DYNAMIC CHANGES .NET optional and named parameters make this much easier var betterWay WordApplication.Documents.Open file ReadOnly true Visible true betterWay.Activate The new dynamic functionality which we will look at shortly can also make your code more readable by allowing you to infer many casting operations. For example the compiler can now work out the type of object you are using duck typing allowing code such as Excel.Range excel.Cells 1 1 .Value2 Excell-ent . to be rewritten as excel.Cells 1 1 .Value Excell-ent Not hugely different but much more readable. We re Out of PIA Another COM-related change worth mentioning is that you no longer need PIA files. In previous versions of Visual Studio when a COM component was referenced Visual Studio would create an additional assembly to describe the COM DLL to the CLR a PIA or Primary Interop Assembly . Unfortunately these PIA files could get pretty large as they described every method of the COM object even if you were not using them. In VS2010 to stop Visual Studio generating PIA files simply set the Embed Interop Types property to True in Solution Explorer. Variance Variance has changed in .NET 4.0. At the 2008 PDC Anders Hejlsberg lead architect of C summarized the changes to variance as Allowing you to do things in your code that previously you were surprised you couldn t do. For those that are already comfortable with the concept of variance stop looking so smug here is the short version of what has changed in .NET 4.0 You can now mark parameters in generic interfaces and delegates with the out keyword to make them covariant and with the in keyword to make them contravariant In and Out in VB.NET . The in out keywords have been added to some commonly used generic interface and delegate types to now enable them to support safe co- and contravariance for example IEnumerable out t and Action in t . If this means nothing to you read on. Variance is a confusing subject and I suspect you can