Tutorial :What is the simplest unique identifier available in .Net?


So I have this

public class Foo  {      public int UniqueIdentifier;        public Foo()      {          UniqueIdentifier = ????      }      }  

How do I get a completely unique number?



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();      }      }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »