C# Programming > Miscellaneous

C# Generate GUID

c# create GUID

C# GUID

GUID stands for Globally Unique Identifier and is a series of numbers and letters that provide a unique serial number. The unique GUID is used by programmers for setting a unique ID to an object. It can be any type of object. GUID can be used for anything in C# that needs to have a unique identifier...

Luckily for C# programmers, .NET has an automatic way to generate GUID.

Create GUID

A GUID is generated in C# via the GUID class. There is no need to pass any parameters:

Guid guid = Guid.NewGuid();
txtGUID.Text = guid.ToString();

The source code above will generate a different GUID every time. Notice that it uses the NewGuid function instead of creating a new instance of Guid class.

The unique string is generated randomly. You might worry that the same GUID will be generate twice, but the chances are extremely low. For example, try to generate this one: 04C1A6A1-3F3B-4D8B-80C0-4917F83545F5.

Back to C# Article List