How to intialize using Object Initializers ?

Posted by Akiii under C# on 7/29/2011 | Points: 10 | Views : 1274 | Status : [Member] | Replies : 2
Hi,

I have a class:-

Person personobj = new Person();
personobj .FirstName = "Akiii";
personobj .LastName = "lethal";
personobj .Age = 90;


We can initialize the above as:-

Person personobj = new Person { FirstName="Akiii", LastName="lethal", Age=90 };


But can anybody tell me how to initialize the below code using object initializers :-

Person personobj = new Person {
FirstName = "Scott",
LastName = "Guthrie"
Age = 32,
Address = new Address {
Street = "One Microsoft Way",
City = "Redmond",
State = "WA",
Zip = 98052
}
};


Looking forward for a reply....
Thanks and Regards
Akiii




Responses

Posted by: Akiii on: 7/29/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi jaydeep....
Thanks for your reply...

I have already seen those post....
But i am looking for the answer of my question...

I hope you understand...
Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response