I need to develop an ever increSing counter in C#. I am thinking about converting GUID to long. Is that possible in c#? Is there any other way to develop an ever increasing counter?
No, a GUID is 128 bit so won't fit in your long since that is 64 bit. A System.Decimal is 128 bit so will get you a long way, but of course that also has it's limits. Even if you save your counter in a string it has its limits. Computers alsways have limits, you will have to find one which is big enough so you can continue for a while.
edit:
In .Net 4.0 there is a BigInteger which can be pretty big, but remember, even that has its limits since it has to fit in memory.
you could try something like this.
byte[] gb = Guid.NewGuid().ToByteArray();
int i = BitConverter.ToInt32(gb,0);
long l = BitConverter.ToInt64(gb,0);
I am not sure If it is very secure. :p
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