Articles → CSHARP → Automatic Properties And Object Initializers In C#

Automatic Properties And Object Initializers In C#




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 5, 2010

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250