-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter11.cs
More file actions
87 lines (76 loc) · 3.18 KB
/
Chapter11.cs
File metadata and controls
87 lines (76 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
namespace Chapter11
{
enum TrafficLight
{
Green,
Yellow,
red
}
[Flags]
enum CardDeckSettings : uint
{
SingleDeck = 0x01,
LargePicture = 0x02,
FancyNumbers = 0x04,
Animation = 0x08
}
class MyClass
{
bool UseSingleDeck = false,
UseBigPics = false,
UseFancyNumbers = false,
UseAnimation = false,
UseAnimationAndFancyNumbers = false;
public void SetOptions(CardDeckSettings ops)
{
UseSingleDeck = ops.HasFlag(CardDeckSettings.SingleDeck);
UseBigPics = ops.HasFlag(CardDeckSettings.LargePicture);
UseFancyNumbers = ops.HasFlag(CardDeckSettings.FancyNumbers);
UseAnimation = ops.HasFlag(CardDeckSettings.Animation);
CardDeckSettings testFlags = CardDeckSettings.Animation | CardDeckSettings.FancyNumbers;
UseAnimationAndFancyNumbers = ops.HasFlag(testFlags);
}
public void PrintOptions()
{
Console.WriteLine("Option settings:");
Console.WriteLine(" Use Single Deck - {0}", UseSingleDeck);
Console.WriteLine(" Use Large Picture - {0}", UseBigPics);
Console.WriteLine(" Use Fancy Numbers - {0}", UseFancyNumbers);
Console.WriteLine(" Show Animation - {0}", UseAnimation);
Console.WriteLine(" Show Animation and FancyNumbers - {0}", UseAnimationAndFancyNumbers);
}
}
class Program
{
static void MainTest()
{
Console.WriteLine("Alex is cool!");
Console.WriteLine("*******************************************");
TrafficLight t1 = TrafficLight.Green;
TrafficLight t2 = TrafficLight.Yellow;
TrafficLight t3 = TrafficLight.red;
Console.WriteLine("{0}, \t{1}", t1, (int)t1);
Console.WriteLine("{0}, \t{1}", t2, (int)t2);
Console.WriteLine("{0}, \t{1}", t3, (int)t3);
Console.WriteLine("********************************************");
CardDeckSettings ops;
ops = CardDeckSettings.FancyNumbers;
Console.WriteLine(ops.ToString());
ops = CardDeckSettings.FancyNumbers | CardDeckSettings.Animation;
Console.WriteLine(ops.ToString());
Console.WriteLine("*********************************************");
MyClass mc = new MyClass();
CardDeckSettings ops1 = CardDeckSettings.SingleDeck
| CardDeckSettings.FancyNumbers
| CardDeckSettings.Animation;
mc.SetOptions(ops1);
mc.PrintOptions();
Console.WriteLine("*********************************************");
Console.WriteLine("Second member of TrafficLight is {0}\n",
Enum.GetName(typeof(TrafficLight), 1));
foreach(var name in Enum.GetNames(typeof(TrafficLight)))
Console.WriteLine(name);
}
}
}