I have a string that is split into an integer array. The size of this array can be 1 item up to 100,000 (or larger). Order is not important.
The objective is to use the object later to determine if the value is present. A separate loop will be testing against this object to see if the item exists (the loop will iterate more than the number of items in testmeInt
array).
Way 1: Array
Attempt to select the integer, catch an error
Way 2: Dictionary
var testme = "12,23".Split(',');
int[] testmeInt = Array.ConvertAll<string, int>(testme, int.Parse);
Dictionary<int, int> TestMeDict = new Dictionary<int, int>();
foreach (int item in testmeInt)
{
TestMeDict.Add(item, 0);
}
for (int i = 1; i <= 50000000; i++)
{
if (TestMeDict.ContainsKey(i) == true) {
//It Exists
}
}
My guess is that the Way2 using Dictionary will be the fastest. This question is similar to mine, but don't cover my exact use case.