19

I am building a DLL which will be used by C++ using COM. Please let me know what would be the C# equivalent of C++ 64-bit unsigned long long.

Will it be ulong type in C# ? Please confirm.

Thanks, Gagan

shb
  • 5,957
  • 2
  • 15
  • 32
Gags
  • 827
  • 2
  • 13
  • 29

4 Answers4

19

Maybe this will help you:

  • ulong (64-bit unsigned integer)
  • double(64-bit floating-point number).
Davide Cannizzo
  • 2,826
  • 1
  • 29
  • 31
Dzmitry Martavoi
  • 6,867
  • 6
  • 38
  • 59
  • is that guaranteed for all time (like Java long type will always be 64 bit)? – Bathsheba Sep 17 '13 at 13:50
  • 9
    Huh? In C#, `ulong` is short for System.UInt64 which is (and always will be) a 64-bit unsigned integer. – dtb Sep 17 '13 at 14:27
  • 1
    @dtb: have you ever seen any official documentation with such guarantee about C# shorts? – Dzmitry Martavoi Sep 17 '13 at 14:37
  • 4
    http://msdn.microsoft.com/en-us/library/ya5y69ds.aspx http://msdn.microsoft.com/en-us/library/exx3b86w.aspx http://msdn.microsoft.com/en-us/library/vstudio/ms228593.aspx – dtb Sep 17 '13 at 14:39
3

For anything that goes beyond ulong, you might as well use the C# BigInteger Structure.

Davide Cannizzo
  • 2,826
  • 1
  • 29
  • 31
HerpDerpington
  • 3,751
  • 4
  • 27
  • 43
  • 1
    Finding factorial of numbers > 20 is not possible without `BigInteger` data type. Thanks for sharing. – RBT Aug 22 '17 at 12:23
  • not true anymore. Since .NET Core 7.0 you there are [System.Int128](https://learn.microsoft.com/en-us/dotnet/api/system.int128?view=net-7.0) and [System.UInt128](https://learn.microsoft.com/en-us/dotnet/api/system.uint128?view=net-7.0) that's wider than `ulong` – phuclv Oct 16 '22 at 01:12
1

In C++, the size of integer types varies depending on whether the program is running on a 32- or 64-bit machine, whereas C# integer types are platform-independent. So, they're not interoperable.

Rather, in C# there are the IntPtr and UIntPtr types, which are intended for P/Invoke, and whose size is 4 bytes on 32-bit machines and 8 bytes on 64-bit machines, which makes them equivalent to the C++ signed long and unsigned long types, respectively.

Davide Cannizzo
  • 2,826
  • 1
  • 29
  • 31
-7

Since C++11, you can use these:

  • int8_t
  • int16_t
  • int32_t
  • int64_t
  • uint8_t
  • uint16_t
  • uint32_t
  • uint64_t

Their size is guaranteed to remain the same regardless of anything.

http://en.cppreference.com/w/cpp/types/integer.

Davide Cannizzo
  • 2,826
  • 1
  • 29
  • 31
Ivan Ishchenko
  • 1,468
  • 9
  • 12