c# - What is the collection equivalent of a multi-dimensional array? -
I have a set of data that looks like this:
001 001 forest 001 002 two 001 003 three 002 001 one 002 002 two 002 003 three ...
Now, of course, I can create an array of string [x] [y] = z But this array needs to be resizable, and I want to use string indices of the index, as the numerical reason is that I will need to see the data through the string, and I No unnecessary string-> Number conversions will not appear.
My first idea was:
dictionary & lt; String, dictionary & lt; String, string & gt; & Gt; Information; Data = new dictionary & lt; String, dictionary & lt; String, string & gt; & Gt; (); Dictionary & lt; String, string & gt; Subdata = Dictionary & lt; String, string & gt; (); Subdata.Add (key, string); Data.add (key2, subdata);
And it works, but some cumbersome, it also feels wrong and kundi and is not particularly efficient.
So what's the best way to store such data in the archive?
I also had the idea of building my own collection class, but not me, but if I did not want to, I would not only use the existing tool.
This is a very common request, and most people end up writing some variations of a tuition class if If you are using ASP.NET, you can use the triple
class already available, otherwise, type something like this:
Public class Tupale & Lt; T, T2, T3 & gt; {Public Tupl (T First, T2 Second, T3 Third) {First = First; Second = second; Third = third; } Receive public t before { Set; } Public T2 Second {Received; Set; } Public T3 third {receipt; Set; }}
is a normal three-tuple class, so you can create a new list & lt; Tupal & lt; String, string, string & gt; & Gt; ()
you can create and add your tuples and add them to that basic class with some basic functionality and you are up and away.
Edit: A list does not look like a proper approach to the dictionary, because there is only one value in each dictionary that there is no multi-entry relationship between the key and values - only a multi-part key And there is an associated value. The data is equal to a database row (or a tupe!).
Edit 2: Here is a indexable list class that you can use for convenience.
Public category MyTupleList: List & lt; Tupal & lt; String, string, string & gt; & Gt; {Public Tulle & lt; String, string, string & gt; This [string first, string second] {returns (it. (X => x.first == before and seconds seconds == seconds)); } Set {this [first, second] = value; }}}
Comments
Post a Comment