I often see people in full swing discussing the new features of Vs.net Whidbey and the. Net FrameWork 2.0, and I'm still here, and I'm not sure I've got the seven-letter "Whidbey" right. :(
Today, just in VPC loaded with vs.net Community Technology Preview, determined to experience a. Net Framework 2.0 and C # 2.0 of the sharp point.
Opening a new vs.net, creating a new WinForm application, immediately discovers the difference: "Code generated by the form designer" where is it? Where's InitializeComponent ()?
After a while, only to find that the original is this partial the key word of the ghost.
The role of the partial keyword is to divide your class into parts, and the compiler will put more than one part together.
public partial class SampleClass
... {
public void MethodA ()
... {
}
}
public partial class SampleClass
... {
public void MethodB ()
... {
}
}
And
public class SampleClass
... {
public void MethodA ()
... {
}
public void MethodB ()
... {
}
}
is equivalent.
I guess this thing came out of the way to fix it: "The code generated by the form designer", this annoying region.
For us, this might be useful in a team development.
I looked at the generated IL code, and there was no special markup for the code generated using partial, which meant that partial was purely a language feature, and that the CLR had absolutely no idea of the existence of such a thing, meaning that partial class could not be compiled into assembly or The partial class, which is written with other people, can be spliced: it only works at compile time.
To test the compiler, I tried to get a partial class to not explicitly specify the parent, and found that the code is still able to compile correctly, the compiler compiles according to an explicitly specified partial of the parent class, and the error occurs only if multiple partial specify different parent classes. Similarly, if multiple partial specify conflicting modifiers, the compile will also cause an error.
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
... {
}
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service