- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Int64.CompareTo Method in C# with Examples
The Int64.CompareTo() method in C# is used to compare this instance to a specified object or Int64 and returns an indication of their relative values.
Syntax
Following is the syntax −
public int CompareTo (long val); public int CompareTo (object val);
Above, in the 1st syntax, the value Val is an integer to compare. The Val in the 2nd syntax is an object to compare.
Example
Let us now see an example to implement the Int64.CompareTo() method −
using System; public class Demo { public static void Main(){ long val1 = 20; long val2 = 18; Console.WriteLine("Value 1 = "+val1); Console.WriteLine("Value 2 = "+val2); Console.WriteLine("Return value (comparison) = "+val1.CompareTo(val2)); } }
Output
This will produce the following output −
Value 1 = 20 Value 2 = 18 Return value (comparison) = 1
Example
Let us now see another example to implement the Int64.CompareTo() method −
using System; public class Demo { public static void Main(){ long val1 = 20; object val2 = (long)20; Console.WriteLine("Value 1 = "+val1); Console.WriteLine("Value 2 = "+val2); Console.WriteLine("Return value (comparison) = "+val1.CompareTo(val2)); } }
Output
This will produce the following output−
Value 1 = 20 Value 2 = 20 Return value (comparison) = 0
Advertisements