Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

Are 2 dimensional Lists possible in c#?

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. One line from the file in each list entry.

I then analyze the list with regular-expressions to find specific lines. Some of the data/results from the lines needs to be put into a new multidimensional list; since I don't know how many results/data I'll end up with, I can't use a multidimensional array.

Here is the data I want to insert:

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>>();

But I haven't really had much more progress :(

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...