--------------------------------------------------------------------------------
Please keep the following information when quoting or reprint:
Dashan [Msn:a3news (at) hotmail.com]
Http://www.zpxp.com http://www.brawdraw.com
Online graphic image processing of radish mouse
--------------------------------------------------------------------------------
1. Automatic attributes (Automatic properties)
believe that C # developers have encountered the following tedious get/set:
(Repetitive mechanical Labor!) I was so upset about it that I simply installed a plugin called Vsproperty in vs.
public class Person
{
private string _truename;
private string _nickname;
private int _age;
public string Truename
{
get {
return _truename;
}
set {
_truename= value;
}
}
public string Nickname
{
get {
return _nickname;
}
set {
_nickname= value;
}
}
public int Age
{
get {
return _age;
}
set {
_age = value;
}
}
}
Thankfully, there's been a change in VS2008, and you can do this:
public class Person
{
public string Truename {get; set; }
public string Nickname {get; set; }
public int Age {get; set; }
}
2.object Initializer (initializers):
Previous initialization mode:
person who = new person ();
Person. Truename = "Johson";
Person. Nickname = "Big can Mountain";
Person. Age = 30;
Now you can:
person person = new Person {truename= "Johnson", nickname = "Dashan", age=30}; It's convenient to have a row!
How do I add a mailing address?
Can be changed to:
person who = new person
{
Truename = "Johnson",
Nickname = "Big can Mountain"
Age = 30,
Address = new Address {
Street = "Shenzhen Press Group No. No. 6008 Futian District Shennan Avenue",
City = "Shenzhen",
Province = "Guangdong province",
Zip = 518009
}
};
Note that address is also a new addition, direct new!
3. Collection Initializers (Collection initializers)
You can use this:
list<person> people = new list<person> ();
People. ADD (new person {truename = "Johnson", nickname = "Dashan", age = 30});
People. ADD (new person {truename = "Bill", nickname = "Brother Bill", age = 40});
People. ADD (new person {truename = "Jim", nickname = "Small Liang elder brother", age = 20});
You can even do this:
list<person> people = new List<person> {
New Person {truename = "Johnson", nickname = "Dashan", age = 30},
New Person {truename = "Bill", nickname = "Brother Bill", age = 40},
New Person {truename = "Jim", nickname = "Little Liang elder brother", age = 20}
};
(and a few add)
In a word, more and more humane!