O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generate a GUID

Problem

You want to create a new Globally Unique Identifier (GUID).

Solution

Use the shared System.Guid.NewGuid method.

Discussion

A GUID is a 128-bit integer. GUID values are tremendously useful in programming because they’re statistically unique. In other words, you can create GUID values continuously with little chance of every creating a duplicate. For that reason, GUIDs are commonly used to uniquely identify queued tasks, user sessions, and other dynamic information. They also have the advantage over random numbers or sequence numbers in the fact that they can’t easily be guessed. For example, if you write an XML Web service that assigns a new GUID to each user session, a malicious user won’t be able to determine what GUID a user ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required