Posts tagged "Object and Collection Initializer in C#"

Object and Collection Initializer in C#

(adsbygoogle = window.adsbygoogle || []).push({}); The Object Initializer and Collection Initializer are similar to initialized Array and Object Constructor where we are able to set the properties of the newly created objects or multiple instances of the new object in essentially one line of code. Object initializers are similar to the constructors that populates the properties of the newly created instances of the object. Unlike the constructor,you can pick and choose which properties to populate in any combination . class Address { public string street { get; set; } public string city { get; set; } } class Users { public int UserID { get; set; } public string UserName { get; set; } public string FirstName { get; set; } public Address ResidentialAddress { get; set; } public Users(int AUserID, string AUserName) { UserID = AUserID; UserName = AUserName; } } read more


1 comment - What do you think?
Posted by Ginktage - June 8, 2010 at 10:06 pm

Categories: C#, Visual Studio, Windows Application   Tags: , , , , , , , , ,