Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 1.43 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Trying to Create an array holding a Struct?
  2. MyArrayStruct[Count].TagName = "Bla Bla";  
  3. MyArrayStruct[Count].TagValue = "Bla Bla Bla";
  4.        
  5. public struct TagContents
  6. {
  7.      String TagName;
  8.      String TagValue;        
  9. };
  10.        
  11. public void LoadXML()
  12. {
  13.     if (File.Exists("Data.xml"))
  14.     {
  15.         //Readin XML
  16.         XmlDocument xmlDoc = new XmlDocument();
  17.         xmlDoc.Load("Data.xml");
  18.         XmlNodeList dataNodes = xmlDoc.SelectNodes("//FieldData");
  19.         //Count the nodes
  20.         int Max = 0;
  21.         foreach (XmlNode node in dataNodes)
  22.         {
  23.             Max = Max + 1;
  24.         }
  25.  
  26.         int Count = 0;
  27.         //TagContents MyXmlPointer = new TagContents();
  28.         // MyXmlPointer[] ArrayNode;
  29.         //  ArrayNode = new MyXmlPointer[Max];
  30.  
  31.         foreach (XmlNode node in dataNodes)
  32.         {
  33.             // ArrayNode[Count].TagName =node.SelectSingleNode("Have not found what to put here yet but will get there").Name;
  34.             // ArrayNode[Count].TagValue =node.SelectSingleNode("Have not found what to put here yet but will get there").InnerText;                      
  35.         }
  36.     }
  37.     else
  38.     {
  39.         MessageBox.Show("Could not find file Data.xml");
  40.     }
  41. }
  42.        
  43. public class TagContent
  44. {
  45.     public String TagName;
  46.     public String TagValue;
  47. };
  48.        
  49. var tags = new List<TagContent>();
  50.  
  51. tags.Add(new TagContent{TagName = "aaa", TagValue = "vvv"});
  52.  
  53. // use it:
  54. // get value of 'TagName' of item 5:
  55. var tagname5 = tags[5].TagName;