![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
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
Advertisements