Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
System Namespace
Guid Structure
Guid Constructor
 Guid Constructor (String)

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Guid Constructor (String)

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public Sub New ( _
    g As String _
)
Visual Basic (Usage)
Dim g As String

Dim instance As New Guid(g)
C#
public Guid(
    string g
)
Visual C++
public:
Guid(
    String^ g
)
JScript
public function Guid(
    g : String
)

Parameters

g
Type: System..::.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:
dddddddddddddddddddddddddddddddd
-or-
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:
dddddddd-dddd-dddd-dddd-dddddddddddd
-or-
{dddddddd-dddd-dddd-dddd-dddddddddddd}
-or-
(dddddddd-dddd-dddd-dddd-dddddddddddd)
-or-
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.
ExceptionCondition
ArgumentNullException

g is nullNothingnullptra null reference (Nothing in Visual Basic).

FormatException

The format of g is invalid.

OverflowException

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.

"ca761232ed4211cebacd00aa0057b223"

"CA761232-ED42-11CE-BACD-00AA0057B223"

"{CA761232-ED42-11CE-BACD-00AA0057B223}"

"(CA761232-ED42-11CE-BACD-00AA0057B223)"

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
OverflowException is only thrown in specific circumstances      David M. Kean   |   Edit   |   Show History

OverflowException is only thrown when one or more of the first three groups of the "{0xdddddddd, 0xdddd, 0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}}" format overflows.

For example, the following values cause an OverflowException to be thrown:

{0x111111111, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
{0x00000000, 0x111111111, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
{0x00000000, 0x0000, 0x111111111, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}

In contrast, the following values cause a FormatException to be thrown:

{0x00000000, 0x0000, 0x0000, {0x111, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
{0x00000000, 0x0000, 0x0000, {0x00, 0x111, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x111, 0x00, 0x00, 0x00, 0x00, 0x00}}
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x111, 0x00, 0x00, 0x00, 0x00}}
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x111, 0x00, 0x00, 0x00}}
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x111, 0x00, 0x00}}
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x111, 0x00}}
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x111}}

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker