Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting GUID to long [closed]

Tags:

c#

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?

like image 845
logeeks Avatar asked Nov 01 '25 17:11

logeeks


2 Answers

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.

like image 137
Lars Truijens Avatar answered Nov 03 '25 07:11

Lars Truijens


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

like image 32
JAiro Avatar answered Nov 03 '25 07:11

JAiro