lundi 18 décembre 2017

how to generate the numeric value which is not exist in given numeric array

i wrote this function out but it takes time to generate new numeric value. how to do in fast way?

 public int GeneratenewID(int[] OptionId)
    {
        Random ran = new Random();
        int SearchId = ran.Next(1, OptionId.Length*2);
        if (!OptionId.Contains(SearchId))
        {
            return SearchId;
        }
        else
        {
          return  GeneratenewID(OptionId);
        }
    }




Aucun commentaire:

Enregistrer un commentaire