Orcas version C # 3.0 new features

Source: Internet
Author: User
Tags new features visual studio

Since the release of the Microsoft March CTP version of Visual Studio and the. NET Framework "Orcas", many bloggers have reviewed and commented on the new features of this version in Run-time macros and code metrics.

Recently, the head of Microsoft ASP.net and Ajax development department Scott Guthrie also published some new features of C # 3.0 in his blog. The new features of the c#3.0 highlighted in the article are as follows:

Automatic properties--Automatic Properties

The Orcas version of C # can automatically establish private domains and default Get/set functions without the user having to manually declare private domains and manually establish Get/set functions. For example, when we are programming using the previous C # language, we need to write the following code snippet manually:

The following is a reference fragment:

public class Person ...{
private string _firstName;
private string _lastName;
private int _age;
public string FirstName ...{
get ...{
return _firstName;
}set ...{
_firstName = value;
}
}
public string LastName ...{
get ...{
return _lastName;
}
set ...{
_lastName = value;
}
}
public int Age ...{
get ...{
return _age;
}
set ...{
_age = value;
}
}
}

Using the Orcas version of C # we can rewrite the code as follows with its automatic property functionality:

The following is a reference fragment:

public class Person ...{
public string FirstName ...{
get; set;
}
public string LastName ...{
get; set;
}
public int Age ...{
get; set;
}
}

or in order to be more concise, we can reduce the blank area, the code is compact as follows:

The following is a reference fragment:

public class Person ...{
public string FirstName ...{
get; set;
}
public string LastName ...{
get; set;
}
public int Age ...{
get; set;
}
}

When the C # "Orcas" compiler encounters a blank Get/set property implementation as shown above, it automatically generates a private domain in your class while implementing a public getter and setter property implementation. The advantage of this is that, from a type-contract perspective, the class seems to use the execution (implementation) in the first paragraph of the code above. This means that, unlike the public domain, we can in the future add validation logic to the property setter implementation without having to change any external components related to the class.

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.