enum jihe
{
a,
b,
c
}
1.jihe是类型,那a,b,c是什么?字段?类型?
2.jihe temp,我想用temp.a=1为什么不能访问?
3.象我那样这样是不是要用结构?
4.为什么jihe temp=jihe.a用console输出来的值却是a却不是0
这次就4分了,以后有分在给大家花撒
{
a,
b,
c
}
1.jihe是类型,那a,b,c是什么?字段?类型?
2.jihe temp,我想用temp.a=1为什么不能访问?
3.象我那样这样是不是要用结构?
4.为什么jihe temp=jihe.a用console输出来的值却是a却不是0
这次就4分了,以后有分在给大家花撒
jihe.a/jihe.b/jihe.c它们的值从资源文件中获取..建一个.resx文件存放枚举值.
/// 根据指定的枚举获取其枚举名称。
/// </summary>
/// <param name="enumTypeName">枚举类型。</param>
/// <param name="enumValue">枚举值。</param>
/// <param name="defaultValue">当找不到枚举时显示的默认值。</param>
/// <returns></returns>
public static string GetEnumName(Type enumTypeName, object enumValue, string defaultValue)
{
try
{
string s = System.Enum.GetName(enumTypeName, enumValue);
if (String.IsNullOrEmpty(s))
return defaultValue;
else
return System.Enum.ResourceManager.GetString(String.Format("{0}_{1}", enumTypeName.Name, s));
}
catch (ArgumentNullException)
{
return defaultValue;
}
catch (ArgumentException)
{
return defaultValue;
}
catch (Exception)
{
return String.Empty;
}
} /// <summary>
/// 根据指定的枚举获取其枚举名称。
/// </summary>
/// <param name="enumTypeName">枚举类型。</param>
/// <param name="enumValue">枚举值。</param>
/// <returns></returns>
public static string GetEnumName(Type enumTypeName, object enumValue)
{
return GetEnumName(enumTypeName, enumValue, String.Empty);
}
{
男=0,
女=1,
变性人=2,
不男不女=3,
不女不男=4,
无法识别=5
}定义一个方法
public string GetSex(SexType SetSex)
{
switch (SetSex)
{
Case SexType.男:
return "力气很大";
Case SexType.女:
return "力气较小";
Case SexType.变性人:
return "力气一般";
Case SexType.不男不女:
return "无法估量";
Case SexType.不女不男:
return "基因变异后力量很大";
Case SexType.无法识别:
return "外星人,力量无穷";
default:
return "这个是哪样社会";
}
}调用:
public void ShowSexInfo()
{
MessageBox.Show(GetSex(SexType.男));
}
{
a,
b,
c
}
1.jihe是类型,那a,b,c是什么?字段?类型?
2.jihe temp,我想用temp.a=1为什么不能访问?
3.象我那样这样是不是要用结构?
4.为什么jihe temp=jihe.a用console输出来的值却是a却不是0
你可以转成int型,就成0了
这次就4分了,以后有分在给大家花撒去看枚举去
是枚举项,枚举项是一个存在的概念,是一种特殊的成员。2.jihe temp,我想用temp.a=1为什么不能访问?
枚举项是只读的3.象我那样这样是不是要用结构?
不清楚你的需求4.为什么jihe temp=jihe.a用console输出来的值却是a却不是0
枚举类型重载了ToString方法以输出枚举项的名称。
要注意枚举类型变量和枚举项的区别。
我就应用过一次!enum Super
{Add,Delete,Update}
public DataSet SuperFuction(SqlCommand dcom,Super a)
{this.com=dcom;
this.con=com.createConnection();
switch(a)
{
case Super.Add:
adpt.AddCommand=com;
case...
}}
举个简单列子,说明枚举可以这样用.public enum SexType
{
男=0,
女=1,
变性人=2,
不男不女=3,
不女不男=4,
无法识别=5
}定义一个方法
public string GetSex(SexType SetSex)
{
switch (SetSex)
{
Case SexType.男:
return "力气很大";
Case SexType.女:
return "力气较小";
Case SexType.变性人:
return "力气一般";
Case SexType.不男不女:
return "无法估量";
Case SexType.不女不男:
return "基因变异后力量很大";
Case SexType.无法识别:
return "外星人,力量无穷";
default:
return "这个是哪样社会";
}
}调用:
public void ShowSexInfo()
{
MessageBox.Show(GetSex(SexType.男));
}
经典!