I have a jagged Array String[][]
. Now I need to find the array with a particular value in String[n][0]
what i have a the moment is a simple
foreach foo in bar{
if(foo[0]==needle){
return foo;
}
}
As you may see this is very slow for obvious reasons. I'm new to C# and just saw the indexOf, but how can i use indexOf in a jagged array?
Another way i tought of is Sorting the Array by String[n][0]
, going to the record in the middle, check if my value is larger or bigger, jump in the half of the upper/lower area and so on, maybe 3 or 4 times so i can find the record faster.
So whats the fastest way of getting the Array in a jagged Array where I only know [][0]
?
I would use a
Dictionary<int, int[]>
where the key is the first item of the array. Dictionaries have constant time access, and are very fast for random access if the entire data fits in memory.