C# Flags Enum Explained - Deep Dive

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024

Комментарии • 43

  • @SridharSathya
    @SridharSathya 9 лет назад +10

    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.

    • @Matlus
      @Matlus  9 лет назад +1

      Right you are Sridhar.

  • @jessegador
    @jessegador 4 года назад +1

    The most compact and best video for masking. Thanks for the great explanation. Now I'm subscribed to your channel.

    • @Matlus
      @Matlus  4 года назад +1

      Thank you for your kind words Jesse! Thank you also for subscribing.

  • @autofires
    @autofires 10 лет назад

    Another brilliant video. Very well prepared with clear explanations and professionally delivery.
    I hope you continue with these lessons. Many Thanks Mr Kumar, धन्यवाद

  • @starman9000
    @starman9000 6 лет назад

    Oh Shiv, you are super star, your simple explanation is made me understand clearly, i will be frequent visitor to your blog. Thank you

  • @zzzamo
    @zzzamo 4 года назад +1

    Really easy to understand. Thanks man!

    • @Matlus
      @Matlus  4 года назад

      Thank you Eduardo!

  • @ontherogs
    @ontherogs 9 лет назад +1

    Really useful, well explained shift left logic

  • @aske1602
    @aske1602 9 лет назад

    Thanks, best tutorial so far on flags. I have some very specific logic that flags will work well with.

  • @matejzajacik8496
    @matejzajacik8496 2 года назад +5

    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.

  • @ijeanpierrebp
    @ijeanpierrebp Год назад

    Great explanation ⭐⭐⭐⭐⭐

  • @vladgheorghiu2215
    @vladgheorghiu2215 6 лет назад

    This is explained so genius. Very nice!

    • @Matlus
      @Matlus  6 лет назад

      Thank you @Vlad

  • @gajarubanjeyakumar7226
    @gajarubanjeyakumar7226 4 года назад +1

    Thankyou

  • @tan3ryigit
    @tan3ryigit 10 лет назад

    thats great u r back :)

  • @LearnWithVarun
    @LearnWithVarun Год назад

    Awesome, helped alot😄😄

  • @billhefner8034
    @billhefner8034 4 месяца назад

    awesome!

  • @jpegacai104
    @jpegacai104 8 лет назад

    Great tutorial!

  • @jayashreereddy5643
    @jayashreereddy5643 7 лет назад

    Excellent !!

  • @borisevraev8190
    @borisevraev8190 6 лет назад

    Thank you!

  • @dmitryisaevski7765
    @dmitryisaevski7765 7 лет назад

    #simply the best)

    • @Matlus
      @Matlus  7 лет назад

      Thank you!

  • @ontherogs
    @ontherogs 9 лет назад

    Real

  • @adrianiordache4391
    @adrianiordache4391 4 года назад

    I don't think you will ever use such thing in your career as a developer.

    • @Matlus
      @Matlus  4 года назад

      Hi Adrian, I'm afraid, I' don't understand your comment. I've read it several times but I don't get it.

    • @Matlus
      @Matlus  4 года назад

      I beg to differ Adrian. I use this a lot and have been using this feature even before C# (that is other languages).

    • @adrianiordache4391
      @adrianiordache4391 4 года назад

      @@Matlus Which problems does this solves exactly that other data structures or statements could not? Is this more efficient?

    • @Matlus
      @Matlus  4 года назад

      @@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.

  • @ioannisstefanou9140
    @ioannisstefanou9140 4 года назад +3

    Amazing explanation. Really enjoyed the pace and progression. Excellent tutorial, thank you!

    • @Matlus
      @Matlus  4 года назад

      Glad you enjoyed it

  • @bomo6453
    @bomo6453 3 года назад +1

    You sir, just saved my life. Thank you so much

    • @Matlus
      @Matlus  3 года назад

      Thank you Bo! Happy to be of help.

  • @sudheernani2470
    @sudheernani2470 2 года назад

    Here I am trying to find what the concept of flags with enum, and this explanation of yours is crystal clear.. Thank you

  • @vishnupv2008
    @vishnupv2008 4 года назад +1

    I used this today. Your video was great help!

    • @Matlus
      @Matlus  4 года назад

      That's great Punnoor! Good to hear this video helped you.

  • @Phcodesign
    @Phcodesign 5 лет назад +1

    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!

    • @Matlus
      @Matlus  5 лет назад

      @Fikret, thank you! I appreciate your comments

  • @mahdimollaeian8840
    @mahdimollaeian8840 2 года назад

    Thanks for the great explanation

  • @rickmemmer5625
    @rickmemmer5625 6 лет назад

    Exceptional! A model of excellence in instruction. Much appreciated!! :o)

  • @vkg.codefactory
    @vkg.codefactory 6 лет назад

    Excellent video, great coverage on enums!

  • @adrianlara6266
    @adrianlara6266 9 лет назад

    gracias muy util tu video, segui asi.