mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[CSharp/en]Added [Flags]
This commit is contained in:
parent
4f8b16f817
commit
dc34af2b5d
@ -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
|
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.
|
// Static members belong to the type itself rather then specific object.
|
||||||
// You can access them without a reference to any object:
|
// You can access them without a reference to any object:
|
||||||
// Console.WriteLine("Bicycles created: " + Bicycle.bicyclesCreated);
|
// Console.WriteLine("Bicycles created: " + Bicycle.bicyclesCreated);
|
||||||
@ -825,7 +841,6 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
|
|
||||||
## Topics Not Covered
|
## Topics Not Covered
|
||||||
|
|
||||||
* Flags
|
|
||||||
* Attributes
|
* Attributes
|
||||||
* Exceptions, Abstraction
|
* Exceptions, Abstraction
|
||||||
* ASP.NET (Web Forms/MVC/WebMatrix)
|
* ASP.NET (Web Forms/MVC/WebMatrix)
|
||||||
|
Loading…
Reference in New Issue
Block a user