WHIDBEY's topical experience (Partial type)

xiaoxiao2021-03-06  128

WHIDBEY's primary experience (Partial type) Visual Studio 2005 [Whidbey] preemptive experience version [Express Beta 1] has a period of time, and free download on Microsoft's official website (download address: http: // Lab .msdn.microsoft.com / vs2005 /). I really like C # this new language. Maybe it can't say that it is a new life, it is a refining in the past language, maybe it is on the shoulder of the giant, so it looks so excellent. C # 2.0 accompanying the experience version brings us new language features (generics: generics: Iterat: partial class: local type; anonymous methods: anonymous method;), make us more easily writing a simple Bright code, of course, these new features give us a far more than simple and bright code. This only understands your experience in the process of our use. Both the 2003 and 2005 new WindowsApplication12003 and 2005 Solution Explorer will build a form of formal forms that inherited from System.Windows.Forms.Form class, which we compare two different IDE environments. How is the code of Form1. Select Form1.cs View Code 2003: Public Class Form1: System.Windows.Forms.Form {Private System.Windows.Forms.Button Button1; ///

// The designer variable. /// private system.componentmodel.container components = null;

Public Form1 () {// // Windows Form Designer Support for // InitializationComponent (); // // Todo: Add any constructor code after INITIALIZECOMPONENT calls //}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

#REGION Windows Form Designer The code ///

/// designer supports the required method - do not use the code editor to modify the // / this method. /// private () {this.button1 = new system.windows.forms.button (); this.suspendlayout (); // // button1 // this.button1.location = new system. Drawing.Point (88, 72); this.button1.name = "button1"; this.button1.size = new system.drawing.size (72, 32); this.button1.tabindex = 0; this.button1.text = "Button1"; this.button1.click = new system.eventhandler (this.button1_click); // // form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new System.drawing.size (292, 273); this.Controls.add (this.button1); this.name = "form1"; this.text = "form1"; this.ResumeLayout (false);} #ENDREGION

///

/// The primary entry point of the application. /// [stathread] static void main () {Application.run (new form1 ());}

Private void button1_click (object sender, system.eventargs e) {}} 2005: Partial class form1: form {public form1 () {initializecomponent ();}

Private void button1_click (Object sender, Eventargs e) {

}} I look at the code files in FORM1 in two environments. The code is very different in Form1. There is only one point in 2005. There is no definition for Button1, and there is no button1_click () obviously questionable. If we quickly found that Class Form1 was defined as partial, the new language feature local type of C # 2.0. Then we click on the show all files button on the 2005 IDE Solution Explorer, and you will find that more file1.designer.cs under Form1.cs is not in the 2003 environment, and we will find it. Another part of Class Form1 is defined. Partial class form1 {///

/// Required Designer variable. /// private system.componentmodel.icontainer components = null; /// /// clean up any resources being used. /// Protected Override Void Dispose (Bool Disposing) {IF (disponents! = null) {components.dispose ();} Base.dispose (Disposing);

#Region Windows Form Designer Generated Code

///

/// Required method for Designer support -. Do not modify /// the contents of this method with the code editor /// private void InitializeComponent () {this.button1 = new System .Windows.Forms.Button (); this.suspendlayout (); // // Button1 // this.button1.location = new system.drawing.point (75, 49); this.button1.name = "button1"; This.button1.size = new system.drawing.size (96, 46); this.button1.tabindex = 0; this.button1.text = "button1"; this.button1.click = new system.eventhandler (this. Button1_click; // // Form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (292, 273); this.controls.add (this. Button1); this.name = "form1"; this.text = "form1"; this.ResumeLayout (false);}

#ndregion

Private system.windows.Forms.Button Button1;} It is now like 2005 to the form of Form1 seems to be all, 2005 in Form1.cs and Form1.Designer.cs adds the description of Class Form1 in 2003 in Form1.cs. Description of Class Form1. This seems that the Partial type allows us to write a description of a class in different places, or even write two or more different files. Partial information is only useful to the compiler. The compiler sees the description of a class when compiling is "broken" (Partial), which will go to other places to collect other fragments of such classes, then put all the classes The fragmentation is combined into a complete class and compiles it. Therefore, Partial is not reflected in the compiled IL. As for the partial type, what is the meaning? We will discuss later. # 结 QQ: 14754875Email: tiy@citiz.netbbs: www.shixm.com/bbs

转载请注明原文地址:https://www.9cbs.com/read-127000.html

New Post(0)