mardi 17 janvier 2017

Lookup only for odd or even numbers into the list

I'm trying to understand how to search separately only for odd or even indexes with random int rndIndx = random.Next(0, 6); value into the List<string> List = new List<string>(); For example content of list:

string 0 even
string 1 odd
string 2 even
string 3 odd
string 4 even
string 5 odd

I'm not sure how to avoid accepting of one or another to not skip process if random value is odd when I have search for random into even indexes

Another way, if I can somehow search only for odd or separately for even indexes for list itself.

If I can find string by index, then I can use conditions rndIndx % 2 == 0 but anyway I can skip needed process if result is not acceptable for condition

The best way to get desired result would be if I can somehow avoid search for excepted numbers of indexes into the list, additionally it could optimize the performance because in case of Odd I don't have any reason to look for Even number into 90000 values, even if I can except it, and vice versa. But I'm not sure how to do it.

Or I need to repeat request for random number with while loop until the value does not match to the searching type number, not sure if it is better way




Aucun commentaire:

Enregistrer un commentaire