
Untitled
By: a guest on
Aug 7th, 2012 | syntax:
None | size: 1.43 KB | hits: 6 | expires: Never
Trying to Create an array holding a Struct?
MyArrayStruct[Count].TagName = "Bla Bla";
MyArrayStruct[Count].TagValue = "Bla Bla Bla";
public struct TagContents
{
String TagName;
String TagValue;
};
public void LoadXML()
{
if (File.Exists("Data.xml"))
{
//Readin XML
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("Data.xml");
XmlNodeList dataNodes = xmlDoc.SelectNodes("//FieldData");
//Count the nodes
int Max = 0;
foreach (XmlNode node in dataNodes)
{
Max = Max + 1;
}
int Count = 0;
//TagContents MyXmlPointer = new TagContents();
// MyXmlPointer[] ArrayNode;
// ArrayNode = new MyXmlPointer[Max];
foreach (XmlNode node in dataNodes)
{
// ArrayNode[Count].TagName =node.SelectSingleNode("Have not found what to put here yet but will get there").Name;
// ArrayNode[Count].TagValue =node.SelectSingleNode("Have not found what to put here yet but will get there").InnerText;
}
}
else
{
MessageBox.Show("Could not find file Data.xml");
}
}
public class TagContent
{
public String TagName;
public String TagValue;
};
var tags = new List<TagContent>();
tags.Add(new TagContent{TagName = "aaa", TagValue = "vvv"});
// use it:
// get value of 'TagName' of item 5:
var tagname5 = tags[5].TagName;