I often see the new features of VS.NET Whidbey and .NET Framework 2.0 in the Heaven, I am still here to determine my "whidbey" in this day. This seven letters don't be knocking. ()
Today, I just installed VS.NET 2005 Community Technology in VPC, and I would like to experience a sharpness of the .NET Framework 2.0 and C # 2.0.
Open the new VS.NET, create a new Winform Application, discover the differences right away: "The code generated by the" Form Designer "Where is it? Where is INITIALIZECMPONENT ()?
Detailed for a while, I found that the ghost that was this Partial keyword.
The Partial keyword is to divide your Class into multiple parts, and the compiler will put multiple parts together.
Public Partial Class Sample ... {public void methoda () ... {}}
Public Partial Class Sample ... {public void methodb () ... {}}
with
Public Class Sampleclass ... {public void methoda () ... {} public void methodb () ... {}}
Is equivalent.
I suspect that the original intention of this thing is to solve: "The code generated by the form designer" is an annoying region.
For us, this thing may also be a bit in the team development.
I observed the generated IL code. It doesn't have a special mark using the code generated by Partial. This means that the partial is purely language, and the CLR does not know the existence of such a gating. This means not to expect to turn partial class. Compile as Assembly or Module to write a partial class written with other people: it can only work when compiling.
In order to test the compiler, I tried to let a Partial class not explicitly specify the parent class, and the discovery code can still be compiled correctly, the compiler will compile the Partial, which specifies the parent class, only in more A partial specifies that different parent classes will be reported. Similarly, if multiple Partial specifies the contradictory modifier, it will also be reported when compiling.
Interestingly, we can also write the following code:
public partial class Sample ... {public partial class SampleSon ... {public partial class SampleGrandson ... {}}} public partial class Sample ... {public partial class SampleSon ... {public partial class SampleGrandson ... {}}}
Rustle Liu, http://ms.mblogger.cn/rustle/