summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLaoujin <woutervs@hotmail.com>2015-01-31 22:34:42 +0100
committerLaoujin <woutervs@hotmail.com>2015-01-31 22:34:42 +0100
commitdc34af2b5de78fb7e7f04e982e145d0bd67a3728 (patch)
tree3e02cc7c038d68245da58fa7bedb3121b68edac0
parent4f8b16f81745c4082945b49e631aadd204564626 (diff)
[CSharp/en]Added [Flags]
-rw-r--r--csharp.html.markdown17
1 files changed, 16 insertions, 1 deletions
diff --git a/csharp.html.markdown b/csharp.html.markdown
index 61db6a8a..4258a0c6 100644
--- a/csharp.html.markdown
+++ b/csharp.html.markdown
@@ -622,6 +622,22 @@ on a new line! ""Wow!"", the masses cried";
public BikeBrand Brand; // After declaring an enum type, we can declare the field of this type
+ // Decorate an enum with the FlagsAttribute to indicate that multiple values can be switched on
+ [Flags] // Any class derived from Attribute can be used to decorate types, methods, parameters etc
+ public enum BikeAccessories
+ {
+ None = 0,
+ Bell = 1,
+ MudGuards = 2, // need to set the values manually!
+ Racks = 4,
+ Lights = 8,
+ Full = Bell | MudGuards | Racks | Lights
+ }
+
+ // Usage: aBike.Accessories.HasFlag(Bicycle.BikeAccessories.Bell)
+ // Before .NET 4: (aBike.Accessories & Bicycle.BikeAccessories.Bell) == Bicycle.BikeAccessories.Bell
+ public BikeAccessories Accessories { get; set; }
+
// Static members belong to the type itself rather then specific object.
// You can access them without a reference to any object:
// Console.WriteLine("Bicycles created: " + Bicycle.bicyclesCreated);
@@ -825,7 +841,6 @@ on a new line! ""Wow!"", the masses cried";
## Topics Not Covered
- * Flags
* Attributes
* Exceptions, Abstraction
* ASP.NET (Web Forms/MVC/WebMatrix)