tailieunhanh - Lập trình .net 4.0 và visual studio 2010 part 6
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 = (tập tin, chỉ đọc: sự thật, nhìn thấy: đúng); (); 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 file ReadOnly true Visible true 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 1 1 .Value2 Excell-ent . to be rewritten as 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 . 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 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 . 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
đang nạp các trang xem trước