Tuesday 29 September 2015

Guid.ToString() Format String can be only "D".. or "X"

Format String can be only "D", "d", "N", "n", "P", "p", "B", "b", "X" or "x".

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Format String can be only "D", "d", "N", "n", "P", "p", "B", "b", "X" or "x".

Source Error:


Line 153:
Line 154:
Line 155:        Response.Write(Guid.NewGuid().ToString("s"));
Line 156:
Line 157:

A simple given example is exploring all :)

Response.Write(Guid.NewGuid().ToString());
//c31e74b4-c834-487e-b713-f8bd70cabbcb
//Default D

Response.Write(Guid.NewGuid().ToString("D"));
//0b2aa961-7fd3-45e4-b02f-5cdfda90cdb9
//32 digits separated by hyphens:

Response.Write(Guid.NewGuid().ToString("N"));
//dddfb1bbee3d470b8865e0baf661d2ab
//32 digits:

Response.Write(Guid.NewGuid().ToString("P"));
//(2ea5773d-dbd9-4ec7-a195-28fa49445003)
//32 digits separated by hyphens, enclosed in parentheses:

Response.Write(Guid.NewGuid().ToString("B"));
//{656fc16e-8e83-4413-869c-06742360f127}
//32 digits separated by hyphens, enclosed in braces:

Response.Write(Guid.NewGuid().ToString("X"));
//{0xc5b86bd1,0xf277,0x4ad9,{0x8a,0xe9,0xf1,0x57,0x1e,0xf2,0xf1,0x4e}}
//Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

References:https://msdn.microsoft.com/en-us/library/97af8hh4(v=vs.110).aspx