What is the easiest unique identifier available in .Net?

So I have this

public class Foo
{
    public int UniqueIdentifier;

    public Foo()
    {
        UniqueIdentifier = ????
    }    
}

How to get a completely unique number?

Thanks!

+3
source share
3 answers
System.Guid  guid = System.Guid.NewGuid();
String id = guid.ToString();
+17
source

Although not int, the method of creating unique identifiers usually uses a GUID. You can use Guid.NewGuid () to create it.

There are various conversion methods, including byte arrays and strings. For more information about GUIDs, you can read them on Wikipedia .

Good luck.

+2
source

Use a structure Guidlike this.

public class Foo
{
    public readonly Guid UniqueIdentifier;

    public Foo()
    {
        UniqueIdentifier = Guid.NewGuid();
    }    
}
0
source

Source: https://habr.com/ru/post/1709480/


All Articles