C # 2.0,. NET Framework 2.0,visual Studio 2005

Source: Internet
Author: User

c#2.0 corresponds to. NET Frmework2.0, the Start version tool is visual Studio2005

C#2.0 mainly adds generics, anonymous methods, partial types (classes, structs, interfaces), nullable types, iterators, property Access Controllers, method group conversions, covariance and contravariance, static classes, delegate inference

1. Generics: generic type

1          Public Static BOOLGreatto<t> (T t,t t1)wheret:icomparable2         {3             if(T.compareto (T1) >0)4             {5                 return true;6             }7             Else8             {9                 return false;Ten             } One}

2, Anonymous methods: Anonymous method

this. Btnvalidatecode.begininvoke (newthis"cancel";}));

3, Partial types: Partial type, you can split the class, struct, interface and other types of definitions into multiple files, using the keyword partial. The most common is the business and designer parts of the form in WinForm

1   Public Partial classForm1:form2     {3 4     }5 6 7  Partial classForm18     {9         /// <summary>Ten         ///the required designer variables.  One         /// </summary> A         PrivateSystem.ComponentModel.IContainer components =NULL; -  -         /// <summary> the         ///clean up all the resources that are in use.  -         /// </summary> -         /// <param name= "disposing" >true if the managed resource should be disposed, otherwise false. </param> -         protected Override voidDispose (BOOLdisposing) +         { -             if(Disposing && (Components! =NULL)) +             { A Components . Dispose (); at             } -             Base. Dispose (disposing); -         } -  -         #regionCode generated by the Windows Forms Designer -  in         /// <summary> -         ///The Designer supports the required method-do not to         ///Use the Code Editor to modify the contents of this method.  +         /// </summary> -         Private voidInitializeComponent () the         { *              This. SuspendLayout (); $             // Panax Notoginseng             //Form1 -             //  the              This. Autoscaledimensions =NewSystem.Drawing.SizeF (6F, 12F); +              This. AutoScaleMode =System.Windows.Forms.AutoScaleMode.Font; A              This. ClientSize =NewSystem.Drawing.Size (284,261); the              This. Name ="Form1"; +              This. Text ="Form1"; -              This. ResumeLayout (false); $  $         } -  -         #endregion the}
View Code

4, Nullable types: Nullable type, the class can be a different value, or null

1          Public int? Age ; 2          Public decimal? Price ; 3          Public bool? Flag;

5, Iterators: iterators


6. Getter/setter Separate accessibility: Property access control

 Public string Get set; }


7, Method group conversions (delegates): Methods set conversion, you can delegate the declaration of a group of methods, implicitly call

1    Public Delegate voidGreethandler (stringname);2 3          Public voidTest ()4         {5Greethandler Greethander =Chinesegreet;6            //Greethandler greethander = new Greethandler (chinesegreet); //you don't have to write like this .7Greethander ("Jim");8         }9          Public voidChinesegreet (stringname)Ten         { OneConsole.WriteLine ("Hello"+name); A}

8. Co-and Contra-variance for delegates and interfaces: Covariance and contravariance of delegates, interfaces


9. Static classes: Stationary class

C # 2.0,. NET Framework 2.0,visual Studio 2005

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.