Thanks but I'd check your explanation around 17:55 and after. Specifically how we'd turn off a bit; most of us get it wrong often. If I want to remove Tuesday XOR will not remove Tuesday if it is not set - in fact it will turn it on. If I want to remove Tuesday if it turned on or off days = days & ~Weekdays.Tuesday//i.e. and with not Weekdays.Tuesday will ensure Tuesday is turned off irrespective if it is on or off.
Another brilliant video. Very well prepared with clear explanations and professionally delivery. I hope you continue with these lessons. Many Thanks Mr Kumar, धन्यवाद
If you just want to know if the bit is set or not, you can also just test against zero; you don't have to test against the bit itself. So instead of: var tuesdayIsInSet = (days & Weekdays.Tuesday) == Weekdays.Tuesday; You can just write: var tuesdayIsInSet = (days & Weekdays.Tuesday) > 0; Or if you need to test for the absence of the bit: var tuesdayIsNotInSet = (days & Weekdays.Tuesday) == 0; This way, you don't need to update the right-hand side every time you change the left-hand side, and it's less typing.
@@adrianiordache4391 It's not about what problem flags enums solve that you can't do any other way. It's about using the correct solution for the job. These are flags enums, that is a combination of bits can be turned on/off. And you want to know with a single conditional statement which bits are off and which bits are on. Or you want to flip a bit (that is no matter what the state of the bit is, you want to flip it. Or set a bit if it's off or turn off a bit if it is set So for example, is a user in a certain role? A user could be in multiple security roles but are they in this role? Suppose you want to perform certain "set"actions. Suppose these actions will fail but you need to keep trying till all actions are complete. Each action is a bit turned off. Keep trying till all bits are off. They key thing to keep in mind is there for 32 bits (things) these is exactly on variable. and not 32 variables (or a structs that has 32 properties). Just one variable but with sets of possible states.
Thanks but I'd check your explanation around 17:55 and after. Specifically how we'd turn off a bit; most of us get it wrong often. If I want to remove Tuesday XOR will not remove Tuesday if it is not set - in fact it will turn it on. If I want to remove Tuesday if it turned on or off
days = days & ~Weekdays.Tuesday//i.e. and with not Weekdays.Tuesday
will ensure Tuesday is turned off irrespective if it is on or off.
Right you are Sridhar.
The most compact and best video for masking. Thanks for the great explanation. Now I'm subscribed to your channel.
Thank you for your kind words Jesse! Thank you also for subscribing.
Another brilliant video. Very well prepared with clear explanations and professionally delivery.
I hope you continue with these lessons. Many Thanks Mr Kumar, धन्यवाद
Oh Shiv, you are super star, your simple explanation is made me understand clearly, i will be frequent visitor to your blog. Thank you
Really easy to understand. Thanks man!
Thank you Eduardo!
Really useful, well explained shift left logic
Thanks, best tutorial so far on flags. I have some very specific logic that flags will work well with.
If you just want to know if the bit is set or not, you can also just test against zero; you don't have to test against the bit itself.
So instead of:
var tuesdayIsInSet = (days & Weekdays.Tuesday) == Weekdays.Tuesday;
You can just write:
var tuesdayIsInSet = (days & Weekdays.Tuesday) > 0;
Or if you need to test for the absence of the bit:
var tuesdayIsNotInSet = (days & Weekdays.Tuesday) == 0;
This way, you don't need to update the right-hand side every time you change the left-hand side, and it's less typing.
great!
Great explanation ⭐⭐⭐⭐⭐
This is explained so genius. Very nice!
Thank you @Vlad
Thankyou
thats great u r back :)
Awesome, helped alot😄😄
awesome!
Great tutorial!
Excellent !!
Thank you!
#simply the best)
Thank you!
Real
I don't think you will ever use such thing in your career as a developer.
Hi Adrian, I'm afraid, I' don't understand your comment. I've read it several times but I don't get it.
I beg to differ Adrian. I use this a lot and have been using this feature even before C# (that is other languages).
@@Matlus Which problems does this solves exactly that other data structures or statements could not? Is this more efficient?
@@adrianiordache4391 It's not about what problem flags enums solve that you can't do any other way. It's about using the correct solution for the job. These are flags enums, that is a combination of bits can be turned on/off. And you want to know with a single conditional statement which bits are off and which bits are on. Or you want to flip a bit (that is no matter what the state of the bit is, you want to flip it. Or set a bit if it's off or turn off a bit if it is set
So for example, is a user in a certain role? A user could be in multiple security roles but are they in this role?
Suppose you want to perform certain "set"actions. Suppose these actions will fail but you need to keep trying till all actions are complete. Each action is a bit turned off. Keep trying till all bits are off.
They key thing to keep in mind is there for 32 bits (things) these is exactly on variable. and not 32 variables (or a structs that has 32 properties). Just one variable but with sets of possible states.
Amazing explanation. Really enjoyed the pace and progression. Excellent tutorial, thank you!
Glad you enjoyed it
You sir, just saved my life. Thank you so much
Thank you Bo! Happy to be of help.
Here I am trying to find what the concept of flags with enum, and this explanation of yours is crystal clear.. Thank you
I used this today. Your video was great help!
That's great Punnoor! Good to hear this video helped you.
When it is clear to yourself then it is pretty easy your words and explanations to be clear to the audience. Thank you for this excellent video!
@Fikret, thank you! I appreciate your comments
Thanks for the great explanation
Exceptional! A model of excellence in instruction. Much appreciated!! :o)
Excellent video, great coverage on enums!
gracias muy util tu video, segui asi.