Hello friends,
I am a student of a university.
I am a beginner of learning C# program. Somehow, my lecturer has given me a question about what is the difference between C# 2010 property and C# 2005 property.
I do not know to to compare it because i have only VS 2010.
Anyone can help me ?
Thank you ...
Loading
SenthilkumarPosted Mar 31, 2012, 3:29 AM
Actually there is no C# 2005 and C# 2010. It is the visual studio version.
It is C# 2.0 and C# 4.0
You know that property is used to set and get the value into the variable. It eliminates to write the separate method to set and get the value to the variable in the class. Thats where the property introduced.
In C# 2.0,
private string _FirstName;
public string FirstName
{
get{ return _FirstName;}
set{_FirstName = value;}
}
In C# 4.0,
public string FirstName
{
get;
set;
}
This C# compiler will place the variable to get and set the value at the run time.
Additionally, visual studio IDE has the property called prop (code snippt for automatically implemented property).
It need to select and click on TAB TAB will generate the following code.
public int MyProperty { get; set; }
Sam HobbsPosted Mar 31, 2012, 7:33 PM