您的位置:首页 > 编程语言

在项目中简单使用枚举的示例代码

2013-06-18 16:29 483 查看
//在公共类中定义枚举

using System;

using System.Collections.Generic;

using System.Text;

namespace WindowsFormsApplication

{

public class UseEnum//定义成Public类型,则可以在当前项目中进行使用

{

//定义一个枚举类型

//枚举中的内容都是自己定义的

public enum TimeofDay

{

Morning,

Afternoon,

Evening

}

}

}

//在Form页面中使用枚举的示例代码

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace WindowsFormsApplication

{

public partial class FormUseEnum : Form

{

public FormUseEnum()

{

InitializeComponent();

}

//使用枚举的方法

private void useEnum_Click(object sender, EventArgs e)

{

WindowsFormsApplication.UseEnum.TimeofDay myEnum = UseEnum.TimeofDay.Afternoon;//拿到枚举中的值

MessageBox.Show(myEnum.ToString());

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐