mercredi 7 juin 2017

How to get random value from specific ranges of dictionary content

If this way I can get random value from given range:

 int r = ran.Next(1, 4); 
 string v;
 if (dict.TryGetValue(r, out v))
 {
    ///...
 }

how to properly get random value of <int, string> dictionary content from specific range, for example only from 4 to 6 and 1 and 2 and avoid look for 3:

Dictionary<int, string> dict = new Dictionary<int, string>()
{
    { 1, "word1" },
    { 2, "word2" },
    { 3, "word3" },
    { 4, "word4" },
    { 5, "word5" },
    { 6, "word6" }
};




Aucun commentaire:

Enregistrer un commentaire