我想建立一个多维列表。 作为引用,我正在研究播放列表分析器。
我有一个文件/文件列表,我的程序将其保存在标准列表中。每个列表条目中的文件一行。
然后我用正则表达式分析列表以找到特定的行。 线路中的一些数据/结果需要放入一个新的多维列表中;因为我不知道最终会得到多少结果/数据,所以我不能使用多维数组。
这里是我要插入的数据:
List ( [0] => List ( [0] => Track ID [1] => Name [2] => Artist [3] => Album [4] => Play Count [5] => Skip Count ) [1] => List ( And so on....
Real Example:
List ( [0] => List ( [0] => 2349 [1] => The Prime Time of Your Life [2] => Daft Punk [3] => Human After All [4] => 3 [5] => 2 ) [1] => List (
So yeah, mlist[0][0] would get TrackID from song 1, mlist[1][0] from song 2 etc.
But I am having huge issues creating a multidimensional list. So far I have come up with
List<List<string>> matrix = new List<List<string>>();
但我并没有真正取得更多进步:(
最佳答案
当然你可以使用 List<List<string>>
然后你会在哪里写:
List<string> track = new List<string>();
track.Add("2349");
track.Add("The Prime Time of Your Life");
// etc
matrix.Add(track);
但是您为什么要这样做而不是构建自己的类来表示轨道,具有轨道 ID、名称、艺术家、专辑、播放次数和跳过次数属性?然后就有一个List<Track>
.
关于c# - c# 中是否可以使用二维列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/665299/