Are 2 dimensional Lists possible in c#?

后端 未结 9 1542
走了就别回头了
走了就别回头了 2020-11-27 12:44

I\'d like to set up a multidimensional list. For reference, I am working on a playlist analyzer.

I have a file/file-list, which my program saves in a standard list.

相关标签:
9条回答
  • 2020-11-27 13:11

    You can also use DataTable - you can define then the number of columns and their types and then add rows http://www.dotnetperls.com/datatable

    0 讨论(0)
  • 2020-11-27 13:19

    Well you certainly can use a List<List<string>> where you'd then write:

    List<string> track = new List<string>();
    track.Add("2349");
    track.Add("The Prime Time of Your Life");
    // etc
    matrix.Add(track);
    

    But why would you do that instead of building your own class to represent a track, with Track ID, Name, Artist, Album, Play Count and Skip Count properties? Then just have a List<Track>.

    0 讨论(0)
  • 2020-11-27 13:19

    You can also..do in this way,

    List<List<Object>> Parent=new  List<List<Object>>();
    
    List<Object> Child=new List<Object>();
    child.Add(2349);
    child.Add("Daft Punk");
    child.Add("Human");
    .
    .
    Parent.Add(child);
    

    if you need another item(child), create a new instance of child,

    Child=new List<Object>();
    child.Add(2323);
    child.Add("asds");
    child.Add("jshds");
    .
    .
    Parent.Add(child);
    
    0 讨论(0)
提交回复
热议问题