日期:2014-05-17 浏览次数:20688 次
[Flags]
public enum DinnerItems
{
None = 0,
Entree = 1,
Appetizer = 2,
Side = 4,
Dessert = 8,
Beverage = 16,
BarBeverage = 32
}
private void button3_Click(object sender, EventArgs e)
{
//Enum.HasFlag 确定当前实例中是否设置了一个或多个位域。
DinnerItems myOrderA = DinnerItems.Appetizer | DinnerItems.Entree | DinnerItems.Beverage | DinnerItems.Dessert;
DinnerItems myOrderB = DinnerItems.Appetizer | DinnerItems.Entree;
bool a = (myOrderA & myOrderB) == myOrderB;
bool b = myOrderA.HasFlag(myOrderB);
Console.WriteLine(a); //Output:True
Console.WriteLine(b); //Output:True
}