I am a new to C#, I need a small help on how can I pass multiple parameters between the classes?
Below is a small example but my parameters will more than the 10. Is there another way to this?
public StreamStructure(String name, string id, string classname, int number)
{
this.name = name;
this.id = id;
this.classname = classname;
this.number = number;
}
List ——
List<abc> don = new List<abc>();
foreach (XmlElement abc_cdb in abc_cdbs)
{
abc.Name = abc_cdb.GetAttribute("NAME");
abc.Id = abc_cdb.GetAttribute("id");
abc.Clssname = abc_cdb.GetAttribute("classname");
abc.number = Convert.ToInt32(abc_cdb.GetAttribute("number"));
don.Add(abc);
}
I have used as suggested in ans but I am trying to create a list in C# my first record gets replaced with the 2nd one, since the fields in MyDTO are defined as public. Do you have any idea how to fix this?
You are probably better off using C# Initializers or a Data Transfer Object than a large number of constructor parameters. Or combine the two.
To create a list of these objects as in your example, create a new DTO within the loop body.