
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
UInt64 Struct in C#
The UInt64 struct represents a 64-bit unsigned integer. The UInt64 value type represents unsigned integers with values ranging from 0 to 18,446,744,073,709,551,615.
Let us now see some examples of UInt64 Struct methods −
UInt64.CompareTo()
The UInt64.CompareTo() method in C# is used to compare the current instance to a specified object or UInt64 and returns an indication of their relative values.
Syntax
Following is the syntax −
public int CompareTo (object val); public int CompareTo (ulong val;
Above, the value for the 1st syntax is an object to compare. The value for 2nd syntax is an unsigned integer to compare.
The return value is 0 if the current instance is equal to value. It’s less than zero if the current instance is less than Val. The return value is more than zero if the current instance is greater than the value.
Example
Let us now see an example to implement the UInt64.CompareTo() method −
using System; public class Demo { public static void Main(){ ulong val1 = 257876; ulong val2 = 5657655; int res = val1.CompareTo(val2); Console.WriteLine("Return value (comparison) = "+res); if (res > 0) Console.WriteLine("val1 > val2"); else if (res < 0) Console.WriteLine("val1 < val2"); else Console.WriteLine("val=val2"); } }
Output
This will produce the following output −
Return value (comparison) = -1 val1 < val2
Example
Let us now see another example to implement the UInt64.CompareTo() method −
using System; public class Demo { public static void Main(){ ulong val1 = 258768768; object val2 = (ulong)1765765; int res = val1.CompareTo(val2); Console.WriteLine("Return value (comparison) = "+res); if (res > 0) Console.WriteLine("val1 > val2"); else if (res < 0) Console.WriteLine("val1 < val2"); else Console.WriteLine("val=val2"); } }
Output
This will produce the following output −
Return value (comparison) = 1 val1 > val2
UInt64.Equals()
The UInt64.Equals() method in C# returns a value indicating whether this instance is equal to a specified object or UInt64.
Syntax
Following is the syntax −
public override bool Equals (object ob); public bool Equals (ulong ob);
Above, the parameter ob for the 1st syntax is an object to compare to this instance and the parameter ob for the 2nd syntax is the 64-bit unsigned integer to compare to this instance.
Example
Let us now see an example to implement the UInt64.Equals() method −
using System; public class Demo { public static void Main(){ ulong val1 = 44565777; ulong val2 = 77878787; bool res = val1.Equals(val2); Console.WriteLine("Return value (comparison) = "+res); if (res) Console.WriteLine("val1 = val2"); else Console.WriteLine("val1 != val2"); } }
Output
This will produce the following output −
Return value (comparison) = False val1 != val2
Example
Let us now see another example to implement the UInt64.Equals() method −
using System; public class Demo { public static void Main(){ ulong val1 = 78796878; ulong val2 = 78796878; bool res = val1.Equals(val2); Console.WriteLine("Return value (comparison) = "+res); if (res) Console.WriteLine("val1 = val2"); else Console.WriteLine("val1 != val2"); } }
Output
This will produce the following output −
Return value (comparison) = True val1 = val2
- Related Articles
- UInt16 Struct in C#
- UInt32 Struct in C#
- Char Struct in C#
- Byte Struct in C#
- Decimal Struct in C#
- C# Int16 Struct
- C# Int32 Struct
- UInt64.CompareTo() Method in C# with Examples
- UInt64.Equals Method in C# with Examples
- UInt64.GetHashCode() Method in C# with Examples
- UInt64.GetTypeCode() Method in C# with Examples
- UInt64.MaxValue Field in C# with Examples
- UInt64.MinValue Field in C# with Examples
- UInt64.ToString() Method in C# with Examples
- Int 64 Struct in C#
