Click here to Skip to main content
14,268,822 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am using System.Guid.NewGuid() to create new unique identifier.

Does it contains any special character like '_' (underscore)?

Thanks in advance,

Pushkar

What I have tried:

int randomNumber = System.Guid.NewGuid();


Is there any possibility that it will contain "_"(underscore).
Posted
Updated 14-May-18 6:30am
Rate this:
Please Sign up or sign in to vote.

Solution 1

No it won't have an underscore. If you are processing a guid as a string there are various parameters you can add to Guid.ToString to control if the hyphen or curly braces are used.

Guid.ToString Method (String) (System)[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Yes, a byte in a Guid could have any value between #0~#255. The string representation of a Guid is really a separate issue.

A Guid is a #16-byte, #128-bit integer.

Take a look:
Guid newGuid = Guid.NewGuid();
Byte[] bytes = newGuid.ToByteArray();
// set break-point here, examine bytes
Suggested reading: [^]
   
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100