4.3.txt
来自「《Microsoft Visual C# .NET 2003开发技巧大全》源代码」· 文本 代码 · 共 46 行
TXT
46 行
Listing 4.3 Representing Configuration Flags Within Your Class
using System;
using System.Collections;
namespace _8_BitArrays
{
enum Ingredients
{
ice, sugar, cream, chocolate, milk, syrup, cinnamon, decaf
}
class Coffee
{
private BitArray ingredientFlags;
public Coffee()
{
ingredientFlags = new BitArray(8);
}
public void AddIngredient(Ingredients Ingredient)
{
ingredientFlags[(int) Ingredient] = true;
}
}
public void ListIngredients()
{
Console.WriteLine( “Coffee Ingredients\n------------------”);
for( int i = 0; i < ingredientFlags.Count; i++ )
{
if( ingredientFlags[i] )
{
Console.WriteLine( “-” +
Enum.GetName(typeof(Ingredients), i) );
}
}
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
Coffee latte = new Coffee();
latte.AddIngredient( Ingredients.sugar );
latte.AddIngredient( Ingredients.cream );
latte.AddIngredient( Ingredients.decaf );
latte.ListIngredients();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?