

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Enum CompareTo Method
Compare two enums using the CompareTo() method in C#.
The method returns any of the following value −
- Less than zero: Value of source is less than value of target
- Zero: Value of source is equal to the value of target
- More than zero: Value of source is more than value of target
Example
using System; class Program { enum Products { HardDrive = 0, PenDrive = 4, Keyboard = 8 }; static void Main() { Products prod1 = Products.HardDrive; Products prod2 = Products.PenDrive; Products prod3 = Products.Keyboard; Console.WriteLine("Stock for {0} is more than {1}?", prod3, prod2); Console.WriteLine( "{0}{1}",prod3.CompareTo(prod2) > 0 ? "Yes" : "No", Environment.NewLine ); } }
Output
Stock for Keyboard is more than PenDrive? Yes
- Related Questions & Answers
- CompareTo() method in C#
- Int16.CompareTo() Method in C#
- C# Enum IsDefined Method
- C# Enum ToString() Method
- C# Enum Parse Method
- C# Enum TryParse() Method
- C# Enum Equals Method
- C# Enum Format Method
- C# Enum GetName Method
- C# Enum GetNames Method
- C# Enum GetValues Method
- LocalDate compareTo() method
- Java String compareTo() method
- Java Integer compareTo() method
- UInt16.CompareTo() Method in C# with Examples
Advertisements