Hello everyone, there is the following example:
class Program { static void Main() { // Enum.GetValues() - возвращает экземпляр System.Array, при этом каждому элементу массива // будет соответствовать член указанного перечисления. // Помещаем в массив элементы перечисления. Array array = Enum.GetValues(typeof(EnumType)); // Получаем информацию о количестве элементов в массиве. Console.WriteLine("Это перечисление содержит {0} членов \n", array.Length); // Вывод на экран всех элементов перечисления for (int i = 0; i < array.Length; i++) { Console.WriteLine("Имя константы: {0}, значение {0:D}", array.GetValue(i)); } // Delay. Console.ReadKey(); } }
Here is the listing itself:
enum EnumType { Zero, // = 0 One = 1, one = One, Two = 2, Three, // = 3 Four, // = 4 Five = 5, //Six, Seven, Eight = 8, Nine, Ten = 10, Infinite = 255 }
I have a question about the cycle
// Вывод на экран всех элементов перечисления for (int i = 0; i < array.Length; i++) { Console.WriteLine("Имя константы: {0}, значение {0:D}", array.GetValue(i)); }
The arrray variable of the Array type contains all elements of the EnumType enumeration, which are presented in the form of a table like any other array, and the GetValue method, using the i-th number, pulls data about the element of the constant array written to the variable array.
So, this array is created as one-dimensional or two-dimensional - because the enumeration constant consists of a name and a value?
GetValues
- where can the second dimension come from? - Grundy