-
基本类型枚举类型和位标志
12
.1
枚举类型
![](https://www.cnblogs.com/images/cnblogs_com/tenghoo/CLR12image001.gif)
internal sealed class AboutEnum
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
static void Main(string[] args)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine("---GetUnderlyingType方法---");
Console.WriteLine(Enum.GetUnderlyingType(typeof(EColor)));
EColor c1 = new EColor();
c1 = EColor.Red;
Console.WriteLine("---ToString方法---");
Console.WriteLine(c1.ToString());
Console.WriteLine("---GetValues方法---");
EColor[] colors = (EColor[])Enum.GetValues(typeof(EColor));
foreach (EColor cc in colors)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine(cc);
}
Console.WriteLine("---GetValues方法---");
Console.WriteLine(Enum.GetName(typeof(EColor),2));
Console.WriteLine("---GetNames方法---");
String[] str = (String[])Enum.GetNames(typeof(EColor));
foreach (string s in str)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine(s);
}
Console.WriteLine("---Parse方法---");
EColor c2 = (EColor)Enum.Parse(typeof(EColor), "1", true);
Console.WriteLine(c2);
Console.WriteLine("---IsDefined方法---");
SetColor((EColor)1);
// SetColor((EColor)10); //引用异常
Console.ReadLine();
}
public static void SetColor(EColor c)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (!Enum.IsDefined(typeof(EColor), c))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw (new ArgumentOutOfRangeException("c", c, "不合法的Color value"));
}
else
Console.WriteLine(Enum.GetName(typeof(EColor), c));
}
}
//EColor和调用它的类型AboutEnum处于同级
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
public enum EColor
{
Write,
Red,
Blue,
Yello
}
12.2位标志
-
相关阅读:
斜二进制数
贝贝的波浪数
1058: 电文保密
1065: 贝贝的加密工作
低危漏洞- X-Frame-Options Header未配置
1064: 不明飞行物(ufo)
支付
1067: 密室寻宝(find)
c++10进制转换为任意2-16进制数字
1066: 单词游戏(game)
-
原文地址:https://www.cnblogs.com/tenghoo/p/1204053.html
Copyright © 2020-2023
润新知