1
using
System;
2
3 public class GetNamesTest
4 {
5 enum Colors
6 {
7 Red, Green, Blue, Yellow
8 };
9 enum Styles
10 {
11 Plaid, Striped, Tartan, Corduroy
12 };
13
14 public static void Main()
15 {
16 Console.WriteLine("The values of the Colors Enum are:");
17 foreach(string s in Enum.GetNames(typeof(Colors)))
18 Console.WriteLine(s);
19 Console.WriteLine();
20 Console.WriteLine("The values of the Styles Enum are:");
21 foreach(string s in Enum.GetNames(typeof(Styles)))
22 Console.WriteLine(s);
23 }
24
2
3 public class GetNamesTest
4 {
5 enum Colors
6 {
7 Red, Green, Blue, Yellow
8 };
9 enum Styles
10 {
11 Plaid, Striped, Tartan, Corduroy
12 };
13
14 public static void Main()
15 {
16 Console.WriteLine("The values of the Colors Enum are:");
17 foreach(string s in Enum.GetNames(typeof(Colors)))
18 Console.WriteLine(s);
19 Console.WriteLine();
20 Console.WriteLine("The values of the Styles Enum are:");
21 foreach(string s in Enum.GetNames(typeof(Styles)))
22 Console.WriteLine(s);
23 }
24
那么加到下拉框也就很简单了。
1
string
[] names
=
Enum.GetNames(
typeof
(DockStyle));
2 comboBox1.Items.Clear();
3 foreach ( string name in names)
4 {
5this.comboBox1.Items.Add(name);
6}
2 comboBox1.Items.Clear();
3 foreach ( string name in names)
4 {
5this.comboBox1.Items.Add(name);
6}