C# equivalent of 64-bit unsigned long long in C++
Asked Answered
N

4

20

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

Nevillenevin answered 17/9, 2013 at 13:47 Comment(1)
ulong is a 64-bit unsigned long int.Matt
S
19

Maybe this will help you:

  • ulong (64-bit unsigned integer)
  • double(64-bit floating-point number).
Swindle answered 17/9, 2013 at 13:49 Comment(4)
is that guaranteed for all time (like Java long type will always be 64 bit)?Rampage
Huh? In C#, ulong is short for System.UInt64 which is (and always will be) a 64-bit unsigned integer.Convulsion
@dtb: have you ever seen any official documentation with such guarantee about C# shorts?Swindle
msdn.microsoft.com/en-us/library/ya5y69ds.aspx msdn.microsoft.com/en-us/library/exx3b86w.aspx msdn.microsoft.com/en-us/library/vstudio/ms228593.aspxConvulsion
F
3

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

Fixer answered 28/8, 2015 at 12:50 Comment(2)
Finding factorial of numbers > 20 is not possible without BigInteger data type. Thanks for sharing.Salter
not true anymore. Since .NET Core 7.0 you there are System.Int128 and System.UInt128 that's wider than ulongExobiology
P
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.

Pneumogastric answered 28/8, 2019 at 6:29 Comment(0)
M
-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.

Mcnutt answered 17/9, 2013 at 13:57 Comment(2)
You got the question backwardsDiscomfiture
Wrong way round, plus not very specific even if wanting to go into the DLLDrillstock

© 2022 - 2024 — McMap. All rights reserved.