I have a class object:
[XmlRoot(ElementName = "Tag")]
public class Tag
{
[XmlElement(ElementName = "TagId")]
public string TagId { get; set; }
[XmlElement(ElementName = "TagTitle")]
public string TagTitle { get; set; }
}
[XmlRoot(ElementName = "LocTags")]
public class LocTags
{
[XmlElement(ElementName = "Tag")]
public Tag[] Tag { get; set; }
}
[XmlRoot(ElementName = "test")]
public class test
{
[XmlElement(ElementName = "ID")]
public string ID { get; set; }
[XmlElement(ElementName = "Name")]
public string Name { get; set; }
[XmlElement(ElementName = "LocTags")]
public LocTags LocTags { get; set; }
}
And I have data already present like this:
test:
id=1
Name="abc"
locTags
tag
tagId=1
tagTitle="xyz"
id=2
name="qwe"
...
I would like to test=1 add new object to Tag, should get result:
test:
id=1
Name="abc"
locTags
tag
tagId=1
tagTitle="xyz"
tagId=2
tagTitle="pqr"
id=2
name="qwe"
...
How do I do that?
Edit
List<Tag> tagNew = test.locTags.Tag.ToList();
tagNew.Add(new Tag
{
TagTitle = "pqr",
TagId = "2"
});
test.locTags.Tag = tagNew;
but the last line gives me error:
Error 10 Cannot implicitly convert type 'System.Collections.Generic.List' to 'Tag[]'
test.locTags.Tag = tagNew.ToArray();