Articles → .NET → Automatic Properties And Object Initializers

Automatic Properties And Object Initializers




Automatic property




private int _age;
public int Age {
	get {
		return _age;
	}
	set {
		_age = value;
	}
}




public int Age {
	get;
	set;
}



Object Initializers




Person person = new Person();
person.Age = 32;
person.Name = " Test";
Response.Write(person.Age);
Response.Write(person.Name);




Person person  = new Person {Name="Test",Age=32} ; 
Response.Write ( person.Age ) ; 	
Response.Write ( person.Name ) ;



Posted By  -  Karan Gupta
 
Posted On  -  Friday, February 05, 2010

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250