I want to define User Define Guid in C#. I want to insert this in my Guid object:
dddddddddddddddddddddddddddddddd.
When I do this:
Guid user = "dddddddddddddddddddddddddddddddd";
I get the err: System cannot convert from String to System.Guid. What should I do here?
It sounds like you want:
Guid user = Guid.Parse("dddddddddddddddddddddddddddddddd");
Note that when you print the guid out again, it will be formatted differently:
// Prints dddddddd-dddd-dddd-dddd-dddddddddddd
Console.WriteLine(user);
You could call the Guid(string)
constructor instead, but personally I prefer calling the Parse
method - it's more descriptive of what's going on, and it follows the same convention as int.Parse
etc. On the other hand, Guid.Parse
was only introduced in .NET 4 - if you're on an older version of .NET, you'll need to use the constructor. I believe there are some differences in terms of which values will be accepted by the different calls, but I don't know the details.
a GUID must be 32 characters formated properly and it would also be called like this
Guid user = new Guid("aa4e075f-3504-4aab-9b06-9a4104a91cf0");
you could also have one generated
Guid user = Guid.NewGuid();
You want to use Guid.Parse for this:
Guid user = Guid.Parse("dddddddddddddddddddddddddddddddd");
Try:
Guid user = new Guid("dddddddddddddddddddddddddddddddd");
Hope this helps!
N.S.
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