Search Forum
(53671 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


 
Printable Version

Creating GUIDs with C#
By Pavel Tsekov

The problem with GUIDs was not an easy one to solve with Visual C++, Visual Basic, etc.

To create and view a GUID(globally unique identifier) you had to call the API UUIDCreate() and then call UUIDToString() to transform the GUID into String.

Now with C# you don't have such sophisticated code.

By the way, you must know that the created GUID is realy globally unique only in case your computer has a Network Adapter. In case it doesn't, the GUID is only locally unique!

Here is an example of creating a GUID in C#:

using System;

namespace PavelTsekov
{
 class MainClass
 {
  static void Main(string[] args)
  {
   //let's create a GUID with C#
   System.Guid guid=System.Guid.NewGuid();
   Console.WriteLine(guid.ToString());
   Console.ReadLine();
  }
 }
}