So i wrote these three functions
Expand|Select|Wrap|Line Numbers
- public static string GiveUniqueID(IEnumerator id_key, int count)
- {
- string id = "";
- bool done = false;
- while (!done)
- {
- id = CreateUniqueID(id_key, count);
- if (id != "@@@")
- done = true;
- }
- return id;
- }
- public static string CreateUniqueID(IEnumerator id_key, int count)
- {
- List<string> ids = new List<string>();
- for(int i = 0; i < count; ++i)
- {
- try
- {
- id_key.MoveNext();
- ids.Add((string)id_key.Current);
- }
- catch (Exception)
- {
- return "@@@";
- }
- }
- bool done = false;
- string id = "";
- while (!done)
- {
- id = UniqueID();
- if (!ids.Contains(id))
- done = true;
- }
- return id;
- }
- public static string UniqueID()
- {
- string toreturn = Session.IdPrefix;
- for (int i = 0; i != 10; ++i)
- toreturn += Utility.RandomList(1, 2, 3, 4, 5, 6, 7, 8, 9, 0).ToString();
- return toreturn;
- }
I am passing the Keys.GetEnumerator(); of dictionaries of varying value types and the count of the dictionary. Since the dictionary's are of varying types i cannot simply pass the dictionary as an argument.
So what i am asking is how to avoid this endless loop?