C# Guid Guid(String)

Description

Guid Guid(String) initializes a new instance of the Guid structure by using the value represented by the specified string.

Syntax

Guid.Guid(String) has the following syntax.


public Guid(
  string g
)

Parameters

Guid.Guid(String) has the following parameters.

  • g - A string that contains a GUID.

Example

The following example shows how to use the Guid(String) constructor.


/* ww w .j a  v  a  2s.co m*/
using System;

public class Example
{
   public static void Main()
   {
      string[] guidStrings = { "ca123456ed4211cebacd00aa3457b123",
                               "CA123456-ED42-11CE-BACD-00AA3457B123", 
                               "{CA123456-ED42-11CE-BACD-00AA3457B123}", 
                               "(CA123456-ED42-11CE-BACD-00AA3457B123)", 
                               "{0xCA123456, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}" };
      foreach (var guidString in guidStrings) {
         Guid guid = new Guid(guidString);
         Console.WriteLine("Original string: {0}", guidString);
         Console.WriteLine("Guid:            {0}", guid);
         Console.WriteLine();
      }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version