dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VBNET
Expertise: Intermediate
Apr 4, 2002

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Create a unique GUID

The System.Guid type exposes several shared and instance methods that can help you work with GUIDs, that is, those 128-bit numbers that serve to uniquely identify elements and that are ubiquitous in Windows programming. The most important member is the NewGuid shared method is useful for generating a new unique identifier:

' Create a new GUID.
Dim guid1 As Guid = Guid.NewGuid
' By definition, you'll surely get a different output here.
Console.WriteLine(guid1.ToString)
    '=> 3f5f1d42-2d92-474d-a2a4-1e707c7e2a37
There are two things you can do with a Guid object: you can convert it to a Byte array with the ToByteArray method, and you can compare two Guid values for equality using the Equals method (inherited from System.Object):

' Convert to an array of bytes.
Dim bytes() As Byte = guid1.ToByteArray
Dim b As Byte
For Each b In bytes
    Console.Write(b.ToString & " ")
        ' => 239 1 161 57 143 200 172 70 185 64 222 29 59 15 190 205
Next

' Compare two GUIDs.
If Not guid1.Equals(guid2) Then
    Console.WriteLine("GUIDs are different.")
End If
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date