Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Get the TypeCode for value type UInt64 in C#
The GetTypeCode() method in C# returns a TypeCode enumeration value that identifies the specific type of a variable. For UInt64 (unsigned 64-bit integer) values, this method always returns TypeCode.UInt64, regardless of the actual numeric value stored.
Syntax
Following is the syntax for getting the TypeCode of a UInt64 value −
TypeCode typeCode = uintValue.GetTypeCode();
Return Value
The method returns TypeCode.UInt64 for all ulong variables, which represents the 64-bit unsigned integer type in the .NET type system.
Using GetTypeCode() with UInt64 Values
Example
using System;
public class Demo {
public static void Main() {
ulong val1 = 55;
ulong val2 = 100;
TypeCode type1 = val1.GetTypeCode();
TypeCode type2 = val2.GetTypeCode();
Console.WriteLine("Typecode for val1 = " + type1);
Console.WriteLine("Typecode for val2 = " + type2);
}
}
The output of the above code is −
Typecode for val1 = UInt64 Typecode for val2 = UInt64
Using GetTypeCode() with UInt64 Boundary Values
Example
using System;
public class Demo {
public static void Main() {
ulong val1 = UInt64.MinValue;
ulong val2 = UInt64.MaxValue;
ulong val3 = 0;
TypeCode type1 = val1.GetTypeCode();
TypeCode type2 = val2.GetTypeCode();
TypeCode type3 = val3.GetTypeCode();
Console.WriteLine("MinValue (" + val1 + ") Typecode = " + type1);
Console.WriteLine("MaxValue (" + val2 + ") Typecode = " + type2);
Console.WriteLine("Zero (" + val3 + ") Typecode = " + type3);
}
}
The output of the above code is −
MinValue (0) Typecode = UInt64 MaxValue (18446744073709551615) Typecode = UInt64 Zero (0) Typecode = UInt64
Comparing TypeCode Values
Example
using System;
public class Demo {
public static void Main() {
ulong ulongVal = 500;
uint uintVal = 500;
long longVal = 500;
Console.WriteLine("UInt64 TypeCode: " + ulongVal.GetTypeCode());
Console.WriteLine("UInt32 TypeCode: " + uintVal.GetTypeCode());
Console.WriteLine("Int64 TypeCode: " + longVal.GetTypeCode());
Console.WriteLine("Are UInt64 and UInt32 same type? " +
(ulongVal.GetTypeCode() == uintVal.GetTypeCode()));
Console.WriteLine("Are UInt64 and Int64 same type? " +
(ulongVal.GetTypeCode() == longVal.GetTypeCode()));
}
}
The output of the above code is −
UInt64 TypeCode: UInt64 UInt32 TypeCode: UInt32 Int64 TypeCode: Int64 Are UInt64 and UInt32 same type? False Are UInt64 and Int64 same type? False
Conclusion
The GetTypeCode() method for UInt64 values consistently returns TypeCode.UInt64, making it useful for runtime type checking and comparison. This method helps identify the specific numeric type regardless of the actual value stored in the variable.
