在项目中简单使用枚举的示例代码
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());
}
}
}
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());
}
}
}
相关文章推荐
- CxImage的简单使用(编译-->项目设置-->代码示例(PNG透明贴图))
- 示例代码中的 SlidingTabLayout 简单使用(二)
- SignalR代理对象异常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的结论 SignalR 简单示例 通过三个DEMO学会SignalR的三种实现方式 SignalR推送框架两个项目永久连接通讯使用 SignalR 集线器简单实例2 用SignalR创建实时永久长连接异步网络应用程序
- 项目代码优化:使用Java枚举常量代替类常量
- 使用Maven构建Spring MVC项目的简单示例
- Java使用设计模式中迭代器模式构建项目的代码结构示例
- 使用简单asp分页代码(项目中)
- 使用Qt示例代码实现的视频播放。VS项目
- Python中使用插入排序算法的简单分析与代码示例
- 使用Maven构建Spring MVC项目的简单示例
- 示例代码中的 SlidingTabLayout 简单使用(一)
- 简单实用的分页控件 AspNetPager.dll 下载地址、使用方法、含有代码示例
- C#使用互斥量(Mutex)实现多进程并发操作时多进程间线程同步操作(进程同步)的简单示例代码及使用方法
- js禁止页面使用右键(简单示例代码)
- js禁止页面使用右键(简单示例代码)
- vue2.0项目中使用Ueditor富文本编辑器示例代码
- vue 项目中使用Loading组件的示例代码
- vue2项目使用sass的示例代码
- 简单讲解gitblit的使用---项目多人开发代码管理工具
- Junit4 简单使用及示例代码