⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4.3.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -