
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 GetValues Method
Get the array of the values of the constants in a specified enumeration.
Here is our enum.
enum Rank { Jack = 10, Tom = 19, Tim = 26 };
Now, get all the values of the enum as an array and display using GetValues() method.
foreach(int res in Enum.GetValues(typeof(Rank))) { Console.WriteLine(res); }
Let us see the entire example.
Example
using System; public class Demo { enum Rank { Jack = 10, Tom = 19, Tim = 26 }; public static void Main() { Console.WriteLine("Here are the university rank of MCA Students College ABC:"); foreach(int res in Enum.GetValues(typeof(Rank))) { Console.WriteLine(res); } } }
Output
Here are the university rank of MCA Students College ABC: 10 19 26
Advertisements