- 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
Byte.CompareTo(Byte) Method in C#
The Byte.CompareTo(Byte) method in C# is used to compare this instance to a specified 8-bit unsigned integer and returns an indication of their relative values.
Syntax
Following is the syntax −
public int CompareTo (byte val);
Above, the parameter value is an 8-bit unsigned integer to compare.
The return value is less than zero if the current instance is less than the value. It’s zero, if the current instance is equal to value, whereas return value is more than zero if the current instance is more than value.
Example
Let us now see an example to implement the Byte.CompareTo(Byte) method −
using System; public class Demo { public static void Main(){ byte b1, b2; b1 = 5; b2 = 7; int res = b2.CompareTo(b1); if (res > 0) Console.Write("b2 > b1"); else if (res < 0) Console.Write("b2 < b1"); else Console.Write("b1 = b2"); } }
Output
This will produce the following output −
b2 > b1
Advertisements