Can somehow an invalid System.Guid object be created in .Net (Visual Basic or C#). I know about Guid.Empty method but it is not what I am searching for. For example with invalid symbols or spaces or being too short or longer than an valid one etc. Thanks!
Can a Guid be created with invalid symbols or spaces or being too short or longer than an valid one etc?
No - a Guid is just a 128-bit number that can be represented in 5 groups of hexadecimal numbers. There's no way for the string representation of a Guid
to contain anything other than 32 hex characters (and possibly 4 hyphens or a few other formatting characters).
You can create a string that does not represent a valid Guid
, but there's no way to put that into a Guid
object.
What does invalid mean to you? That's defined by what your code can deal with. A Guid
is just 16 arbitrary bytes without any mandatory format. You define what kinds of Guid
you want to accept.
In that sense any Guid
object is valid by itself. There's no invalid state for this struct.
It is like an int
. Any int
is valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With