There is a difference between Int64
and UInt64
in C#. Int64
stands for signed eight bytes integers. This means that we can use it to store both positive and negative integers within the range of -9223372036854775808
to 9223372036854775807
.
Similarly, UInt64
is also an integer of eight bytes, but an unsigned kind of integer. This means that it is only for positive numbers or values. The range of this datatype is 0
to 18446744073709551615
.
Int64 variableUInt64 variable
variable
: This is the variable we want to create as an Int64
or UInt64
.
using System;class HelloWorld{static void Main(){// create Int64 VariablesInt64 i1 = 25;Int64 i2 = 100;Int64 i3 = 255;// create UInt64 VariablesUInt64 ui1 = 212;UInt64 ui2 = 12;UInt64 ui3 = 100;// print values, datatypes and rangesConsole.WriteLine("{0} is {1}, with range of {2} to {3}", i1, i1.GetTypeCode(), Int64.MinValue, Int64.MaxValue);Console.WriteLine("{0} is {1}, with range of {2} to {3}", i2, i2.GetTypeCode(), Int64.MinValue, Int64.MaxValue);Console.WriteLine("{0} is {1}, with range of {2} to {3}", i3, i3.GetTypeCode(), Int64.MinValue, Int64.MaxValue);Console.WriteLine("{0} is {1}, with range of {2} to {3}", ui1, ui1.GetTypeCode(), UInt64.MinValue, UInt64.MaxValue);Console.WriteLine("{0} is {1}, with range of {2} to {3}", ui2, ui2.GetTypeCode(), UInt64.MinValue, UInt64.MaxValue);Console.WriteLine("{0} is {1}, with range of {2} to {3}", ui3, ui3.GetTypeCode(), UInt64.MinValue, UInt64.MaxValue);}}
Int64
variables and initialize them.UInt64
variables and initialize them as well.