C# Tutorial: Events/Event Handlers

Поделиться
HTML-код
  • Опубликовано: 2 сен 2019
  • In this lesson I go over events/event handlers and how to use them.

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

  • @problemchild959
    @problemchild959 2 года назад +58

    Just a tip for anyone watching this as its a very simple guide to Events in C#, he actually missed a CRUCIAL point in this tutorial. you should always always check the EventHandler (ClickEvent in this case) for null with the Invoke. if you do not and nothing has subscribed to the event, it will crash the program. you can either do if (ClickEvent !- null) ClickEvent.Invoke() or shorthand it with ClickEvent?.Invoke() (the ? at the end is a shorthand version of only do this if its not null)

  • @sentrycod2373
    @sentrycod2373 3 года назад +12

    You can't learn from this. This will only make sense once you already fully know about Events.

  • @luisarias9682
    @luisarias9682 Год назад +1

    Where I am confused is... why was there no event here? only a delegate?

  • @Brian-nz6ns

    You forgot to explain how event handlers work.....

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

    set speed 1.25, at least

  • @REktSigMa

    But how do you create the button itself as an object?

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

    I don't quite see the difference between events and event handlers and boring old callbacks with custom delegate functions?

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

    That's cutosom!

  • @sheffieldk.408
    @sheffieldk.408 3 года назад +2

    I have a "button" class that I'm creating dynamically. Each button will report a different string to a handler when it has been hovered over. What I've been doing is giving my button class a reference to the parent, and then will call "ReportUp(str)", but I don't think this is a good design. Does this solution help with this or not really? I'm also using Unity but I don't think that matters

  • @dnxsol
    @dnxsol 4 года назад +5

    Clear as mud

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

    Thank you so much, I have read through documentation and watched several videos, but this explanation and demonstration finally made me understand how to actually use them!

  • @killermaker7218
    @killermaker7218 3 года назад +3

    You are my hero man i could finally understand this, really thank you

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

    Awesome! Short and sweet! Very helpful!

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

    Thanks. This was really enlightening.

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

    Thanks for posting this. I'm not sure why you don't have more subs.

  • @randlmorales4890
    @randlmorales4890 Год назад +2

    Question: why is there a need to use the custom EventArgs when you can simply utilize the class where the EventHandler belongs? To be specific in this example: why create a new MyCustomArguments class when you can instead add the Name property in Button and then on the anonymous function just call

  • @MikeKm-hd1ve

    Thank you for this clear explanation!

  • @omerask3992
    @omerask3992 3 года назад +5

    It's a hard topic. Best expression imo

  • @christopherkaggwa6137
    @christopherkaggwa6137 3 года назад +5

    This example is more relevant and understandable even more than the ones in the official content

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

    Bro think for the video I finally learnt what I need !