Given an int
, how can you create the same Guid repeatedly?
Edit:
I'm integrating two systems, one uses ints as a primary key, the other recognises an object by it's Guid. Because of this, I need to be able to recreate the same Guid for a given int so that the second system can recognise the entities coming from the first.
If you want the guid to consist of just the int then:
int x = 5;
string padded = x.ToString().PadLeft(32,'0');
var intGuid = new Guid(padded);
intGuid.ToString(); // 00000000-0000-0000-0000-000000000005
If you create a Guid based on an integer it will no longer be a globally unique identifier.
Having said that you can use the constructor that takes an integer and some other parameters:
int a = 5;
Guid guid = new Guid(a, 0, 0, new byte[8]);
Not really advisable...
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