C # Since the birth of the home to take the long, set thousands of love in one, but also a noble family. NET Framwork is a member of the clan, is born noble. The programming world of Big Brother Java, after more than 10 years of development, has been robust and powerful. With the open source community's ssh (struts+ spring+hibernate) framework, the Java EE has unparalleled charm. Versatility, portability and scalability have been well supported. Every time we learn ssh, we get a sense of why. NET does not have such a good frame. So. NET fans have also developed their own sh (nspring+nhibernate). But these two frameworks and. NET programming style always seems to be out of tune, this is simply copied things. But we also need not be too pessimistic, the appearance of c#3.0 brought us many new features, as to what is the new features, I will give you a description.
First new feature: Automatically generate properties
Typically, we write Get/set methods for each class to provide access and operations to the property externally. Such as:
Code
public class UserInfo
{
string userName;
string password;
public UserName
{
get{return userName;}
set{username=value;}
}
public Password
{
get{return password;}
set{return password=value;}
}
}
We always envy Eclipse. The functionality of the Geter/seter method is automatically generated for the Java properties, although Visual Studio can do similar functions, but it is not easy to use, especially when a class has a lot of properties, writing these get/ Set method is really a very annoying thing. And c#3.0 's automatic generation attribute, finally let us get rid of this nightmare, and you will find it is the language itself, more simple, simpler and more natural than the Java Geter/seter method. Microsoft has made a lot of effort in detail.
Well, let's see what it's like to write the above class using c#3.0 's automatic generation properties.
Code
public Class UserInfo
{
public string UserName{get;set;}
public string Password{get;set;}
}
We can see that this is really too easy. All we need to do is add the Get/set two keywords to the attribute and implement the previous method of writing a few lines of code. The. NET framwork automatically generates its private properties for us. Using it now is the same as using the class above.
Code
UserInfo userInfo=new UserInfo();
userInfo.UserName=”test”;
userInfo.Password=”test”;
Now, we can show it to the Java fans. Oh, a joke.