Thursday, April 21, 2011

Guid.ToString(String) Documentation WTF?

From msdn (here is the link)

Guid.ToString(String) valid input:
'N' - 32 digits:
00000000000000000000000000000000

'D' - 32 digits separated by hyphens:
00000000-0000-0000-0000-000000000000

'B' - 32 digits separated by hyphens, enclosed in braces:
{00000000-0000-0000-0000-000000000000}

'P' - 32 digits separated by hyphens, enclosed in parentheses:
(00000000-0000-0000-0000-000000000000)

'X' - Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:
{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}

Supported .NET Framework: 4, 3.5, 3.0, 2.0, 1.1, 1.0
Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

But on my Windows Vista SP2 & .Net 4 the following code gives nice exception (not valid input):

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Guid.NewGuid().ToString("N"));
            Console.WriteLine(Guid.NewGuid().ToString("D"));
            Console.WriteLine(Guid.NewGuid().ToString("B"));
            Console.WriteLine(Guid.NewGuid().ToString("P"));
            Console.WriteLine(Guid.NewGuid().ToString("X"));
        }
    }
}