<strong><span style="font-size:18px;color:#000099;">例子1:</span></strong>
enum Gender // 定义一个叫Gender的枚举,它有两个值,男和女
{
男,女
} // 一般枚举类型定义和类在同一级别
</pre><pre class="csharp" name="code"> class Program
{
static void Main(string[] args)
{
Gender p; // 声明 枚举 P
p = Gender.男; // 将枚举男赋值给P
if (p == Gender.男) //判断
{
Console.WriteLine("男");
Console.ReadKey();
}
}
}
</pre><pre class="csharp" name="code">------------------------------------------------------------------------------------------------------
private void button1_Click(object sender, EventArgs e)
{
DialogResult re = MessageBox.Show("哈哈", "标题", MessageBoxButtons.OK); // 定义 DialogResult re枚举类型
if (re == DialogResult.OK) //如果点了确定
{
MessageBox.Show("1");
}
}