Wednesday, 19 March 2008

Automatic Property in .Net 3.0

Class Sample
{


Private int m_UserId;

Public int UserId
{
get{ return m_UserId; }
set{ m_UserId = value; }
}


}


Now the new .Net 3.0 approach is

Class Sample
{

Public int UserId
{
get;
set;
}

}

Saves few lines of regular code and you can change the scope of get or set to make the property read only etc.

Default values for reference types are going to be null and value types to be according to the normal behaviour of .Net.