There are several objects I have to add to a list that contain the same information—I would like to know a way how I can optimize the problem. See code below.
"GroupNumber" and "IsAvailable" are all going to be the same.
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
List<ClassA> listAs = new List<ClassA>();
listAs.Add(new ClassA() {GroupNumber = 1, Name = "PersonA", IsAvailable = true});
listAs.Add(new ClassA() {GroupNumber = 1, Name = "PersonB", IsAvailable = true});
listAs.Add(new ClassA() {GroupNumber = 1, Name = "PersonC", IsAvailable = true});
}
}
public class ClassA
{
public int GroupNumber {get; set;}
public string Name {get; set;}
public bool IsAvailable {get; set;}
}
I want to know if there is a shortcut where I could add only "Name" with leaving "GroupNumber" and "IsAvailable" the same.
listAs.Add(new ClassA() {Name = "PersonA"});
listAs.Add(new ClassA() {Name = "PersonA"});
listAs.Add(new ClassA() {Name = "PersonA"});