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 :(
Lists that require two indices to identify an element are called two-dimensional lists (or double-indexed lists or double-subscripted lists). Multidimensional lists can have more than two indices.
A list keeps track of multiple pieces of information in linear order, or a single dimension. However, the data associated with certain systems (a digital image, a board game, etc.) lives in two dimensions.
In C Two Dimensional Array, data is stored in rows and column-wise. We can access the record using both the row index and column index (like an Excel File).
Declare a 2D List With List<List<T>> in C# Unfortunately, there is no built-in method to declare a multidimensional list in C#.
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>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With