List of lists to multidimension array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • e930194
    New Member
    • Feb 2010
    • 2

    List of lists to multidimension array

    I need to convert

    List<List<MyCla ss>> tracks = new List<List<MyCla ss>>(nCount);

    to a jagged array.

    something like...

    MyClass[][] foo = tracks.ToArray( );
    Last edited by e930194; Feb 23 '10, 07:08 AM. Reason: Should be jagged array and not multidimensional array
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    hey you can't directly assign like that....

    but you can do something like this...

    Code:
        List<List<string>> lst = new List<List<string>>();
                string[,] str = new string[lst.Count, lst[0].Count];
                for (int j = 0; j < lst.Count; j++)
                {
                    for (int i = 0; i < lst[j].Count; i++)
                    {
                        str[j, i] = lst[j][i].ToString();
                    }
                }

    Comment

    • e930194
      New Member
      • Feb 2010
      • 2

      #3
      It works fine for multidimensiona l arrays but not for jagged arrays.
      i.e. it works fine for string[,] but not string[][]
      I do apologise for the title reading multidimensiona l arrays. I only realised my mistake afterwards.
      Anyways you answer put me on the road to my solution. Thanks

      Comment

      Working...