C# Flags Enum
Vložit
- čas přidán 2. 02. 2023
- In C#, an enum represents a single named value. But with a little bit of work, we can store multiple value in a single enum variable.
Source code available at: github.com/JasperKent/Flags-Enum
Topics include:
- Enum flags convention
- Combining enums with | (or)
- Querying enums with & (and)
- Querying enums with HasFlag
- Improving appearance with the FlagsAttribute
- Selecting enum size - Věda a technologie
Flags enums have been around since the beginning of C#. Are there any other old but obscure features that need looking into? Let me know
Source code available at: github.com/JasperKent/Flags-Enum
Remember to subscribe at czcams.com/channels/qWQzlUDdllnLmtgfSgYTCA.html
And if you liked the video, click the 👍.
Thanks for the tuto it helped. Though I'm reading existing code which is
Public enum A{
B = 1
@@darkmalk94 The
One of the best tutorials I've ever seen on a specific topic. Kudos
Found your channel recently and I really enjoy the way you present topics.
Thank you for all the lessons
If there was a definitive list of C# tutorials, this video belongs in the enum section. It is thorough and well presented. This is why I just subscribed to your channel (actually, your tutorials are top notch, but this just drives the point home.)
Another great Friday because of Coding Tutorials!
Really great explanation of the topic! Thanks, Jasper!
This tutorial is the best!!!!
Thanks man. I had problem to understand those Flags and related operators, but this tutorial explained it very clearly.
Thank you for this it helped me out big time
Brilliant ✌🏼
thanks babe
Great video on C#! I just started my channel dedicated to programming and I'm always looking for inspiration. Can't wait to see more of your content, keep it up!
nice!!!!!!!!!!!!!
Are there any downsides to numbering them instead with bit-shifting: 0, 1 (or 1
Very good point. I tend to agree, but in the majority of code I've encountered, the numbers are just hardcoded.
I'd say avoid. Flags enums are limited to 32-bit when you use int-Enums. When you reach the limit of 32 entries, you have to workaround that limit, like reserving the last flag and using a second enum to hold the next set of data. Just use a simple class with bool Properties. Easy to understand, easy to extend in all sort of different ways. You could also use just ISet as a replacement on any enum. It will do the same and you can store the whole int-Range of entries in it.