How to write a C# class that has repeated property? For example here is how the serialized object of this class should look like.
<Vehicle>
<Name>Forcus</Name>
<Name>Tomry</Name>
<Name>Hovic</Name>
<Name>Nima</Name>
</Vehicle>
How to write a C# class that has repeated property? For example here is how the serialized object of this class should look like.
<Vehicle>
<Name>Forcus</Name>
<Name>Tomry</Name>
<Name>Hovic</Name>
<Name>Nima</Name>
</Vehicle>
You cannot have multiple properties with the same name.
But you can have a collection property, of type string[]
or List<string>
to store multiple values.
As a concrete example:
public class Vehicle
{
[XmlElement("Name")]
public List<Vehicle> Names {get { return names; }}
private readonly List<Vehicle> names = new List<Vehicle>();
}
just add Name(s) to collection
public class Vehicle
{
public List<string> Name {get;set;}
}