

- 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 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
- Related Questions & Answers
- C# Enum IsDefined Method
- C# Enum ToString() Method
- C# Enum Parse Method
- C# Enum TryParse() Method
- C# Enum CompareTo Method
- C# Enum Equals Method
- C# Enum Format Method
- C# Enum GetName Method
- C# Enum GetNames Method
- Can we define an enum inside a method in Java?
- Enum in Java
- Enum in C#
- Enum in C
- Enum in Python
- Enum Methods in Java
Advertisements