Unique ID

The index is not unique for array's items, when you can delete and insert items to your array. There is a class in Delphi which you can search your array by an ID generated and managed by Delphi.

How can I set a unique ID to my array's elements in .NET



Answer this question

Unique ID

  • Bernie West

    You can use a Hashtable, here you can define you own key. This can be the .GetHashCode() result for example.

  • FJK

    If you want to create your own ID look into creating a GUID. That way you are guaranteed unique values as the id. To build on PJ's suggestion:


    string ID = Guid.NewGuid().ToString();

    Dictionary<string, string> myHash = new Dictionary<string,string>();

    myHash.Add( ID, "This is radio Clash");
    myHash.Add(Guid.NewGuid().ToString(), "On pirate Satellite");

    foreach (KeyValuePair<string, string> entry in myHash)
    Console.WriteLine("Key: {0}\tValue: {1}",entry.Key.ToString(), entry.Value.ToString());




    Output

    Key: 227fe2fb-c5df-4fe9-8f44-afa9a09be092 Value: This is radio Clash
    Key: 33feb5d1-17ba-42f0-966e-a6c1fba2b116 Value: On pirate Satellite



  • Unique ID