. Net3.5 New Features

Source: Internet
Author: User

Object Initial Value Setting item

Studentname student =NewStudentname
{
Firstname ="Craig",
Lastname ="Playstead",
Id = 116
};

List <studentname> students = New List <studentname> ()
{
New Studentname {firstname = "Craig", lastname = "playstead" , Id = 116 },
New Studentname {firstname = "Shu", lastname = "ito" , Id = 112 ,},
New Studentname {firstname = "Stefan", lastname = "RI ß Ling" , Id = 113 ,},
New Studentname {firstname = "Rajesh", lastname = "Rotti" , Id = 114 ,}
};

Use lambda expressions:
Delegate t delegatemul <t> (t x, t y );

Static t multi_mul <t> (T [] Nums, delegatemul <t> func)
{
...
}

Static void main (string [] ARGs)
{
Int [] Nums = new int [5] {1, 2, 3, 4, 5 };
Int pro;
Pro = multi_mul <int> (Nums, (int A, int B) =>{ return a * B ;});
Console. writeline ("product:" + Pro );
Console. Read ();
}

Extension Method:

The extension method is a static method defined inside the static class. developers can use the extension method as they do with the instance method. According to the C # syntax, an instance method can only be called by creating an instance object and cannot be called by class name. On the contrary, a static method can only be called by class name. The extension method provides a new mechanism for calling static methods on the object instance. The extension method is mainly used without changing the existing type.Code. The extended function is only valid for the current context and does not change the code defined for the original type. Its general declaration format is as follows:
Public static class name
{
Public static return type Extension Method Name (this parameter name of the type to be extended)
{
Function body;
}
}

 

Anonymous type:
VaR v = new {amount = 108, message = "hello "};
An anonymous type is a class type consisting of one or more public read-only attributes. Other types of class members (such as methods or events) are not allowed ).

 

Division classes and Methods:

You can set Or , Or the method definition is split into two or more source files. Each source file contains a part of the type or method definition to compile the application.ProgramAll parts are combined.

PublicPartialClassEmployee
{
Public VoidDowork ()
{
}
}

PublicPartialClassEmployee
{
Public VoidGotolunch ()
{
}
}

 

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.