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();
你想使用Guid.Parse :
Guid user = Guid.Parse("dddddddddddddddddddddddddddddddd");
Try:
Guid user = new Guid("dddddddddddddddddddddddddddddddd");
Hope this helps!
NS
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.