edgervivyk
New Member
Presume you 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 guaranteed.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 hit it many times and have more items than the testmeInt array).Way 1: ArrayAttempt to select the integer, catch an errorWay 2: Dictionary\[code\] 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 } }\[/code\]There are similar posts out there, but they mention caring about the lookup value, which I don't care about.My guess is that the Way2 using Dictionary will be the fastest.These posts are similar, but don't cover my exact use case:Dictionary, List or Array?Fastest way to check for value existence