- 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
UInt32.CompareTo() Method in C# with Examples
The UInt32.CompareTo() method in C# is used to compare the current instance to a specified object or UInt32 and returns an indication of their relative values.
Syntax
Following is the syntax −
public int CompareTo (object val); public int CompareTo (uint val;
Above, the Val for the 1st syntax is an object to compare. The Val 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 Val.
Example
Let us now see an example to implement the UInt32.CompareTo() method −
using System; public class Demo { public static void Main(){ uint val1 = 25; uint val2 = 55; 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) = -30 val1 < val2
Example
Let us now see another example to implement the UInt32.CompareTo() method −
using System; public class Demo { public static void Main(){ uint val1 = 25; object val2 = (uint)2; 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) = 23 val1 > val2
Advertisements