So I have this
public class Foo
{
public int UniqueIdentifier;
public Foo()
{
UniqueIdentifier = ????
}
}
How do I get a completely unique number?
Thanks!
So I have this
public class Foo
{
public int UniqueIdentifier;
public Foo()
{
UniqueIdentifier = ????
}
}
How do I get a completely unique number?
Thanks!
System.Guid guid = System.Guid.NewGuid();
String id = guid.ToString();
Although not an int, a method of creating unique identifiers commonly uses GUIDs. You can use Guid.NewGuid() to generate one.
There are some various conversion methods including byte arrays and strings. For more information on GUIDs you can read up on them at Wikipedia.
Best of luck.
Use the Guid
struct, like this.
public class Foo
{
public readonly Guid UniqueIdentifier;
public Foo()
{
UniqueIdentifier = Guid.NewGuid();
}
}