• Create dynamic array of arrays or list of lists in C#

    ShikhaTan Member

    In C# I am trying to create a array of arrays or it can be called as jagged array using XML data. But I am totally confused how to start

    
    
    name1 data1 newdata1 category1 name2 data2 newdata2 category2 name3 data3 newdata3 category2//same category as above ... ... name20 data20 newdata20 category16

    Now I need to create an array with category1, category2, … upto what the categories is there on Category Node, need to create a separate arrays of each category to store the item name and data so I can retrieve them for my use.

    From above sample xml I need the same category items in a single array

    Items and Category count is fully dynamic. How to do this dynamically?

    i just need the array like this

    input output
    a[0]= category1
    a[0][0]= name1
    a[0][0][0]= data1
    a[0][0][1]= newdata1
    
    it means the array should be build like the below
    a={
    category1{name1{data1,newdata1}},
    category2{name2{data2,newdata2},name3{data3,newdata3}}
    category16{name20{data20,newdata20}}
    } 
    

    how to do this programmatically
    and how to use that array data from another class
    or is there any way to create lists dynamically with dynamic name from xml

  • Abhey Member

    Multidimensional Arrays
    https://msdn.microsoft.com/en-us/library/2yd9wwz4.aspx

    FYI a multidimensional array is probably not the best approach for this

    Try using a class which contains a List

    E.G.
    Create a Category and Item class
    Category class contains a List of Items

    List
    https://msdn.microsoft.com/en-us/library/6sh2ey19(v=vs.110).aspx

    Dictionary is also worth looking at:
    https://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
en_USEnglish