protected void Page_Load(object sender, EventArgs e)
{
//枚举字符串数组
var arr = new string[] { "oldWoman", "man", "woman" };
// 枚举位运算 |
Person per = (Person)Enum.Parse(typeof(Person), string.Join(",", arr), true);
//根据枚举位运算| 得到的值,获取枚举字符串
string content = string.Empty;
foreach (var item in Enum.GetValues(typeof(Person)))
{
var person = (Person)item;
if (per.HasFlag(person) && (int)item != 0)
content += person + "";
}
}
// 枚举的每一项值, 用2的n次方来赋值
[Flags]
public enum Person
{
none = 0,
man = 1,
woman = 2,
oldMan = 4,
oldWoman = 8
}