Add properties while Initialize Objects by Using an Object Initializer . But how can we add DataCollection property?
Example:
class Student{
public string FirstName{ get; set} ;
public string LastName{ get; set};
public DataCollection<string> Subjects{ get; set} ;
}
Student myStudent = new Student
{
FirstName = "John",
LastName = "Something"
//Subjects.AddRange()
};
So if we want to add property for "Subjects" how can we add in the above condition?
Generally we can do like below.
Student clsStudent = new Student();
clsStudent.FirstName = "Foo";
clsStudent.LastName = "other";
clsStudent.Values.AddRange(new string[] { "c#" });