This documentation is archived and is not being maintained.

Guid Constructor (String)

.NET Framework 1.1

Initializes a new instance of the Guid class using the value represented by the specified string.

[Visual Basic]
Public Sub New( _
   ByVal g As String _
public Guid(
   string g
public: Guid(
   String* g
public function Guid(
   g : String


A String that contains a GUID in one of the following formats ('d' represents a hexadecimal digit whose case is ignored):

32 contiguous digits:



Groups of 8, 4, 4, 4, and 12 digits with hyphens between the groups. The entire GUID can optionally be enclosed in matching braces or parentheses:







Groups of 8, 4, and 4 digits, and a subset of eight groups of 2 digits, with each group prefixed by "0x" or "0X", and separated by commas. The entire GUID, as well as the subset, is enclosed in matching braces:

{0xdddddddd, 0xdddd, 0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}}

All braces, commas, and "0x" prefixes are required. All embedded spaces are ignored. All leading zeroes in a group are ignored.

The digits shown in a group are the maximum number of meaningful digits that can appear in that group. You can specify from 1 to the number of digits shown for a group. The specified digits are assumed to be the low order digits of the group. If you specify more digits for a group than shown, the high-order digits are ignored.


Exception Type Condition
ArgumentNullException g is a null reference (Nothing in Visual Basic).
FormatException The format of g is invalid.


The alphabetic hexadecimal digits in the g parameter can be upper or lower case.

For example, the following strings represent the same GUID.





"{0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}"


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Guid Structure | Guid Members | System Namespace | Guid Constructor Overload List