C# Events - Creating and Consuming Events in Your Application

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

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

  • @AmandeepSingh-xk4yv
    @AmandeepSingh-xk4yv 4 года назад +20

    I personally feel the universities themselves should pay you for making such quality content accessible to computer science students all over the world! God bless!

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

      Thank you for the kind words.

    • @drip888
      @drip888 2 года назад +1

      He is literally the best teacher for computer science ever. I mean he still replies to my comments. He is the first person i donated some money too.

  • @wayahedia9989
    @wayahedia9989 4 года назад +18

    I've been coding for decades. WPF since about 2012. Always under pressure to get code delivered and make sure I don't break code I already have. I have rarely had time to become expertly proficient in most of the things I code and oh yeah.. xaml is my nemesis. I've got a few weeks of time before the next big project begins and I want to step up my game each time I start a new app as there won't be a lot of time for massive changes along the way. Corey's tutorials are so helpful for me to gather my wits and learn more before I begin again. Thanks Corey.

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

      Excellent!

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

      i dont mean to be so off topic but does anyone know of a method to get back into an instagram account..?
      I somehow lost my password. I would appreciate any assistance you can give me

  • @user-tf9lo4fi4m
    @user-tf9lo4fi4m 3 года назад +5

    WHen i found ur channel i felt like i've won in lottery. Such nice and clear explanations, really love it, thank u very very much, Tim. U r doing nice

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

      I am glad you found it so helpful.

  • @RalfsBalodis
    @RalfsBalodis 4 года назад +9

    0:00 - Intro
    1:19 - Demo application walk through (WinForms)
    3:18 - Code behind the demo app
    18:28 - Event: Button click
    21:21 - Creating and Invoking custom Event
    26:35 - Event " ?.Invoke() " explained
    30:00 - Listening to and writing code for the Event
    34:00 - Creating the custom Event: Event in action and recap
    37:12 - Event argument information: debugging
    38:42 - Creating Another custom Event (overdraft event)
    43:28 - Listening for the event in multiple places
    46:33 - Removing Event Listeners form memory
    49:00 - EventHandler: Passing class for T
    53:39 - why not to use "public set" for properties
    59:25 - Exception when to use public set
    1:06:13 - Summary

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

      Thanks! I added it to the description.

  • @mixsawkfg8877
    @mixsawkfg8877 4 года назад +4

    Greatest teacher ever! I have listened you and i went on step 1 instead on going on step 3 or 4 as you said in your first video of Getting started with C# even if i knew something about C# but i was rusty. Everything is understandable and personally i receive knowledge very easy.
    PS: I am really glad that every few days you have 1k more subscribers, you really deserve it ! Every here and when i recommend you to my friends or people that are interested in programming. Keep up the good work, you are rare diamond on RUclips. Best regards !

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

      I am glad it has been helpful. Thanks for recommending the channel.

  • @minitycui9862
    @minitycui9862 3 года назад +7

    Hi, Tim. You are the best C# instructor.

  • @avchung
    @avchung 10 дней назад

    Hi Tim, thank you very much for this, I watched the other videos on Events and now this one, and NOW I have a really good understanding how events work and how to reduce the linear flow of my applications through events. I really did not understand how this worked until now. Books or other youtube videos fall way short of the way you have designed and presented this demo application to show us how to use events in a real world application. Also, grateful for the source code that you supply with these videos so that we can learn by doing. I hear, I forget; I see, I remember; I do, I understand!

  • @bleepbloop6303
    @bleepbloop6303 2 года назад +3

    Great content man. I'm interviewing for a senior .NET developer position next week and am watching some of your content on things I haven't ran into in my daily work and your content is super helpful and informative. Good stuff dude. People like you change so many lives by helping them gain marketable skill sets in the real world.

    • @tomthelestaff-iamtimcorey7597
      @tomthelestaff-iamtimcorey7597 2 года назад

      Good luck with the interview! Please let us know how it goes. Check out Tim's Dev Questions videos about interviewing to help you get in the right frame of mind - ruclips.net/user/IAmTimCoreysearch?query=interview

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

      @@tomthelestaff-iamtimcorey7597 It turned out not to be a technical interview but rather a more conversational interview.
      I think spending hours by myself in the dark looking at code may have ended up being more of a detriment than anything else hahaha.
      It did go well though; waiting to hear back but it was very recently so here's hoping.

    • @IAmTimCorey
      @IAmTimCorey  2 года назад +1

      @@bleepbloop6303 Thanks for the update. Let us know!

  • @chickazama
    @chickazama 3 года назад +2

    I just stopped by this video to refresh myself on some concepts with events. I don't comment on every video of yours because I'd be pretty much repeating myself every time but: I started learning to code last October. I settled on learning C# somewhat arbitrarily (originally I wanted to have a go at making video games in Unity), and quickly realised that programming was something I was passionate about.
    Thanks to you, in less than a year I have become confident in a whole host of topics, from building ASP.NET Core (Razor & MVC) web apps, carrying out data access, and unit testing my code; to designing applications with a clean decoupled architecture and a focus on separation of concerns. Not only that, I am now starting to be offered Software Development jobs (something I thought would be impossible without a Computer Science degree) and feel like not only do I have a decent knowledge of these topics but I know what to do and where to look to improve on that knowledge!
    So, yes, I just wanted to say many thanks for uploading these videos! I have subscribed to your mailing list - and I direct friends/anyone interested to your channel and website when they ask about C#. Absolutely stellar job - you have literally opened up a career for me and for that I am extremely grateful! I look forward to seeing what you continue to produce! - Matt

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

      This is why I am passionate about my work. I love hearing these stories. Thank you for sharing your journey!

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

      Good job keeping it DRY! Ha, sorry, couldn't help myself :)

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

    Hi Tim, I've been a subscriber to your channel for a while now, but obviously only since after the publication of this video. I had reached a point in my current project where I felt I could probably achieve my target through exceptions, but couldn't work out how to do it. I looked at a load of text tutorials on-line, each more overly complicated than the last. Then I found your video here. It was super easy to follow, really clearly explained, and I managed to implement exceptions in my own project, alongside watching you explain it. Thank you very much :)

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

      Awesome! I'm glad it was so helpful.

  • @orany321
    @orany321 10 месяцев назад +1

    27:11 "There's no point of saying if something new happen, if no one cares" well that's one sentence I'll remember forever :) great as usual Tim, it's nice to refresh to my knowledge about C#, even if it's my everyday, used at work language. One video a day makes it easier to remember all these amazing features and their concepts.

    • @IAmTimCorey
      @IAmTimCorey  10 месяцев назад

      I'm glad it made an impression.

  • @mayurbanta
    @mayurbanta 6 лет назад +1

    Thanks Tim. Best explanation of C# Events. I have checked Pluralsight, Linkedin Learning and several online content for C# events and this is by far the best explanation of how practically to use events.

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

      Thanks! I appreciate the kind words.

  • @jaisgeorge1166
    @jaisgeorge1166 4 года назад +2

    Great teaching. For others who think Tim's videos r long, who come here to pick quick things, no this is organic teaching, not junk food learning.

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

      Thank you!

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

      There's a middleground. 17 minutes in and this guy still hasn't said anything.

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

    Thank you very much for an explanation of the very details of this pretty complicated concept Mr. Corey!

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

    You're such a good teacher. Just wanted to let you know. Keep it up

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

    Tim Corey your videos are amazing I love the free content so much a bought a few of your courses during the black Friday sale. Thank you I have learned so much from your content!

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

      Awesome! I'm glad have learned a lot from my content.

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

    I take it slow and spend my two day for events. Now i understand whole thing. Perfect.

  • @madskyper6482
    @madskyper6482 10 месяцев назад

    Thank you so much. I was struggling to make custom Events for so long. But with this VERY clear explanation , I can finally do it easily.

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

    Tim Corey, great job on explaining events and showing how to add custom events. I love C# and use it everyday. This video gave me some new info that will be very helpful!! Thanks.

  • @mohammadranjbaran1897
    @mohammadranjbaran1897 2 года назад +2

    Dear Tim, once again, thank you very much.

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

    This video is really incredible, as always. Thank you Tim.

  • @elkhoukhi
    @elkhoukhi 4 года назад +4

    Quality! beautiful teaching

  • @Alibek11221
    @Alibek11221 4 года назад +2

    The best events tutorial i`ve ever seen. Beelive me i red and seen a lot of them, and couldn`t understand a damn thing. Thank you!

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

      You are welcome.

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

      IAmTimCorey Even though the other tutorials were in Russian) Imagine how good this tutorial has to be if English is my 3’rd language))) Imagine how bad is my English but still i had no problems with understanding how events work)

  • @shaktisingh-lu3dm
    @shaktisingh-lu3dm 3 года назад +1

    Very helpful course with nice n clear explanation. Many thanks Tim.

  • @ES-rk4gh
    @ES-rk4gh 2 года назад +1

    Thank you very much I was so confused until I watched this

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

    Very good, this es the only one that so far Made me undertand about event handlers, I watch it every time I want to implement one

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

      I am glad you found it useful.

  • @addkim7889
    @addkim7889 4 года назад +2

    I love your way of teaching, it's very simple and practical, but in my opinion, you should put your video about event after delegate.
    Event and delegate are not only very closely related, under the hood delegate is the foundation for event and explaining event - again in my opinion only - without mentioning delegate first is harder and easier to get confuse

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

      I understand. The reason I usually switch the order, though, is because people are used to events. Doing something when a button is clicked is usually one of the first things a developer learns (not my recommended order). So, wrapping your mind around events is easier than delegates. Once you know how events work, you can expand to delegates are easier to understand (which is a good thing since they are complicated).

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

      @@IAmTimCorey thank you for your response. Wow that's kind of weird to learn event like that, because the first question that would pop up in my mind is: "what is that EventHandler thing" but I can see why event would come up so early for window app developer. Thank you again

  • @peteredenburg6464
    @peteredenburg6464 6 лет назад +1

    Hey Tim,
    Great video again. I've always had trouble wrapping my head around the whole 'events' thing. In the past I've read some pretty compicated stuff, but that was all explained from the point, which is still true of course, that it all starts at the point where you get to learn about delegates, after which it gets increasingly complicated. For me, that is. But your video made it much clearer.
    Just to be shure I'm doing the unsubscribing of the events the proper way, this is the code I devised for that purpose:
    private void Transactions_FormClosing(object sender, FormClosingEventArgs e)
    {
    _customer.CheckingAccount.OverdraftEvent -= CheckingAccount_OverdraftEvent;
    }
    I had to go for the _customer, since customer is a function parameter of the constructor and therefore not accessible outside of that.
    private void Dashboard_FormClosing(object sender, FormClosingEventArgs e)
    {
    customer.CheckingAccount.TransactionApprovedEvent -= CheckingAccount_TransactionApprovedEvent;
    customer.SavingsAccount.TransactionApprovedEvent -= SavingsAccount_TransactionApprovedEvent;
    customer.CheckingAccount.OverdraftEvent -= CheckingAccount_OverdraftEvent;
    }
    Or is it better to do this inside the _FormClosed event?
    BTW, is there a way to check if there are memory leaks should one omit this sort of code?
    Thanks,
    Peter

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

      The FormClosing event is the place to do it. You don't really need to do it in your main form, since when that form closes the application closes but that all looks right. As for checking for memory leaks, I'll be doing a video on that in the future. You can use a profiler to track your usage.

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

    Thank you for this video, it's really nicely put together.
    I also like you clear calm way of speaking :)
    Subbed

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

      You are most welcome. Thanks for watching.

  • @RioTheHitman
    @RioTheHitman 6 лет назад +2

    Thanks for sharing your knowledge

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

    Thanks alot Tim, keep up the great work, you are fantastic.

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

    Hi Cory, Really enjoyed your vids and have learned alot. I have used c before but now I am looking into the interface to my windows laptop.
    At the present time I program my own devices and enjoy learning programing. I only write my own files at this time. for my stuff. Thanks again, Len

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

    Thanks TIm on another great tutorial. This is so simple and consise explanation of C# events.
    Cheers

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

    Mr. Corey, your C# channel is perhaps my most favorite! By the way, will you ever make a video on the Bitmap class (because there are not sufficient videos on RUclips covering image manipulation with C#)? Perhaps image manipulation is not a topic that is strictly relevant to the engineering side of things, but it's still useful for UI/UX!

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

      I will add it to the list. Thanks for the suggestion.

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

    Subscribed and liked. The video is long but worth. You did make it coherent and precise. Again thank you.

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

      You are most welcome. Thanks for watching.

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

    Thanks Tim, now more comfortable to use events in our code.

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

    This is just an amazing explanation with lots of tips, thanks a lot, Tim!!

  • @Chickenism
    @Chickenism 5 месяцев назад +1

    Thanks for video. It really help me understand events.

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

    I'm actually falling in love with this stuff

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

    Nice to know about events. I guess we can use it whether windows form or wpf but i dont feel comfortable with windows forms. Drag and drop feels just not corret. Anyways, everything will be more clear on user interface section :))

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

      I started on WinForms and doubting what to do next. I understand the feeling of it not being correct, but the WinForms designer is so easy to use for starters..

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

      You can use Events in any part of C#, not just in the user interface.

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

    Another great video. Now I understand events better. Thanks Tim!

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

    Brilliant job Tim. Thanks a lot for sharing it!

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

    You are the best at explaining! Thank you so much!

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

    Thank you! I have reinforced my Events handling knowledge.

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

      I'm glad it reinforced some things for you.

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

    Great video Tim, very simple to understand. Thanks!

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

    Thank you for all your videos, they've been quite helpful.

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

      You are most welcome. Thanks for watching.

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

    An hour long, but totally worth it.

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

    You are the best! Thanks you so much :) Really helped me understand events a bit better!

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

    Another great video. You are super. Thanks for the Video Tim.

  • @rinzler9775
    @rinzler9775 Год назад +3

    Cleaning and unsubscribing events I find the most challenging to avoid memory leak scenarios.

    • @IAmTimCorey
      @IAmTimCorey  Год назад +3

      Yep, they are challenging.

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

      @@IAmTimCorey I got caught in my own events web once or twice 😂

  • @pierreplourde
    @pierreplourde 2 года назад +2

    Question about removing event listeners: you mentioned on a form’s Close event; can you also do it as part of the form’s destructor, since a form is a class?

  • @mr-loki
    @mr-loki 4 года назад

    Tim, once again - thank you! Cool lesson.

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

    Thanks a million for such quality education! You're awesome!

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

    This video really helped me a lot, Thank you so much!

  • @nafisiancastle
    @nafisiancastle 2 года назад +1

    We need a discord server for the audience of this channel so that we can question and discuss more.

    • @IAmTimCorey
      @IAmTimCorey  2 года назад +2

      That's not something I'm able to do at this time. One step at a time.

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

    Hello Tim, I started watching your videos recently and they have been very good.
    I went to your patreon page and was looking through the Tiers. I think you have a small typo on the first Tier for $1:
    "
    Did you know paying just $1/month provides me with more income than RUclips ads do for all of your views? So if you are wondering if this matters, is absolutely does.
    "
    I assume the last three words of that string are supposed to be "it absolutely does" instead of "is absolutely does".
    Just thought you would like to know. Thanks for the videos!

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

      Thanks for the heads up. I fixed it.

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

    Thank you Tim for making C# Events so easy to understand that C# beginner can understand. I had a confusion though:
    Am I right in saying that, removal of Events such as recordTransactionsButton_Click, errorMessage_Click is taken care of by Visual Studio but the events such as TransactionApprovedEvent, OverdraftEvent that we create must be removed by us.
    Also, where in the code should I put customer.CheckingAccount.OverdraftEvent -= CheckingAccount_OverdraftEvent; to remove CheckingAccount_OverdraftEvent?

  • @maclo4
    @maclo4 3 года назад +2

    I strive to be as good as tim corey

  • @SomeGuy-be5cq
    @SomeGuy-be5cq 6 лет назад

    Great video as always Tim!

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

    The initial code downloaded from your blog, On Transaction WinForm I noticed the event is firing always unless we add a check in make purchase button.
    private void makePurchaseButton_Click(object sender, EventArgs e)
    {
    if (this.amountValue.Value >= 1)
    {
    bool paymentResult = _customer.CheckingAccount.MakePayment("Credit Card Purchase", amountValue.Value, _customer.SavingsAccount);
    amountValue.Value = 0;
    }
    }
    Excellent Quality Video on Events!!
    Thank you for such videos.

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

      You are most welcome. Thanks for watching.

  • @heradsinn
    @heradsinn 4 года назад +4

    As far as I've understood it and from my experience in other languages, events are mostly used in GUI contexts, like button clicks and similar. Would you say it is wrong or bad practice to use events for other purposes than GUI, more specifically for monitoring the data on the model side of an application?
    For example, my current practice project is a small game. I'm thinking that using events to listen to a character's health points can then invoke an event CharacterDiedEvent and modify other classes accordingly, for example. So I will use the event purely for the model and not for the view.

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

      If match your requirements, why not?

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +4

      No, it isn't bad practice. Events are used for a lot more than just GUIs.

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

      Event driven programming is used as a design practice for decoupling, publish/subscribe design pattern...from what I've read.

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

    I like the new event shorthand notation.

  • @goodmanshawnhuang
    @goodmanshawnhuang 2 года назад +1

    Thanks a lot Tim. One question please, If the part we clean up the event listeners by -= the handlers is so standard, why didn’t Microsoft do for us? I mean like using statement. Thanks again.

  • @computergururick
    @computergururick 2 года назад +1

    Excellent teaching.

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

    I Have All Of Your Videos and I Like Your C# Skills

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

    Watched for 20 mins and still no trace of “events”. I appreciate your attempt. May be you can start with a very simple example and add things on top of it. You did that in many other videos.......

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

      Same here. I love your videos but they could be a little bit more compact focusing on the topic. 20 mins explaining the Demo project is too much. Other tutorials explain events in 20 mins.

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +9

      I understand. The challenge here, though, is to give a "real" example so that the explanation of events in context made sense. I can teach events quickly, but to do so robs the viewer of the chance to see it in context and context is the most important part. Otherwise, you understand the topic but not how to use it in the real world. I understand the desire for the setup to be quicker, though.

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

      to have a straight to the point explanation you always have the microsoft doc docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/event

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

    I think I'll just unsub from other coding channels. Consistently your tutorials allow me to understand and use the concepts than other tutorials, whether they are longer or shorter. Grateful!

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

      I am glad my content has been so helpful to you.

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

    Mr. Corey, could you please introduce a book for those who like to go deeper into these concepts of C# programming? Thank you so much

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

    You are making my code better. Thanks.

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

    Great video, thank you for your work!

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

    Great video, keep it up.

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

    Dude thank you so much!

  • @paulofernandoee
    @paulofernandoee 2 года назад +2

    Great tutorial

  • @FullMe7alJacke7
    @FullMe7alJacke7 5 лет назад +11

    23:25 is when he actually gets to the events

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +17

      There is a lot of setup to get through first. Context is important.

  • @LuigiZambetti
    @LuigiZambetti 6 лет назад +1

    A possible topic for upcoming videos: The Art of Clean Code (obviously in C#). What you think?

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +5

      That's definitely a possibility.

  • @MisterMusicArchive
    @MisterMusicArchive Год назад +3

    9:40 shouldn't balance be greater than or equal to amount?

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

    Great video on events.

  • @drip888
    @drip888 2 года назад +3

    Thanks!

    • @IAmTimCorey
      @IAmTimCorey  2 года назад +1

      Thank you!

    • @drip888
      @drip888 2 года назад +1

      @@IAmTimCorey sorry, i know the amount is bit low, i dont have a job, when i start making money , i will do a better one :)

    • @IAmTimCorey
      @IAmTimCorey  2 года назад +10

      No need to apologize. I'm not looking for money from people. My primary goal is to make learning C# easier, not just for those who can afford it, but for everyone. My paid services, plus the various ways you can give back, are simply a way for the community to help fund that free content for others. It isn't for everyone to use, just for those who can.

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

    I think I got it after pay more attention on. customer.CheckingAccount property is Account type. thanks !

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

      Glad you figured it out.

    • @chunghanwu8588
      @chunghanwu8588 4 года назад +2

      Thank you so much, the lesson does help me a lot........

  • @kopilkaiser8991
    @kopilkaiser8991 Год назад +4

    ⭐️⭐️⭐️⭐️⭐️ video

  • @Anton-Os
    @Anton-Os Год назад +1

    Thank you so much!

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

    Great tutorial. Would you recommend this approach in a blazor client side app?

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

    very informative and helpful. in the start to finish course, you always used the wiredup() method, does that means we can call an event there as well or eventhandler will not work there. thanks for all the good work that you put in your videos and they really are helpful.

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

      You are most welcome. Thanks for watching.

  • @JohnDoe-qn2ej
    @JohnDoe-qn2ej 3 года назад +2

    For some reason when I enter 175 or any amount more than my checking account and click purchase it says "withdrew 100"

    • @IAmTimCorey
      @IAmTimCorey  3 года назад +2

      Sounds like a good time to track down what is going on and fix the bug.

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

      This happens to me also, any solution?

  • @jimmywongseewoei4069
    @jimmywongseewoei4069 3 года назад +2

    Hi Tim, May I ask why we need to use IReadOnlyList for Transactions? This property (Transactions) do not have set for outside of class to change the value.

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

      To prevent another programmer in the bank accidentally/intentionally modifying a list that comes from that class. It is not powerful protection by itself (because you can make anew list with the same contents) against error/fraud but once you combine it with the full suite of fraud/error controls at the bank it becomes more useful.

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

      @@michaelnurse9089 Ok yours makes sense but makeing a property type just IList ( instead of IReadOnlyList) and returning _transactions.AsReadOnly () in getter will not be sufficient protection. I mean if we return _transaction.AsReadOnly() in getter, why we should use IReadOnlyList type rather than just regular IList ???

  • @mohammedamayri2237
    @mohammedamayri2237 2 года назад +3

    Thanks

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

      A Question :
      You mentioned that when passing an object through the event; that the setters in the properties of that object need to be private to prevent every listener from modifying them. My question is; when passing the object, isn't it a copy of the object?(by value) and thus the changes on that object by the listeners shouldn't affect the original object? Maybe i missunderstod something. Thank you for your valuable knowledge!

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

      Thank you! As for the object copying, objects are actually never copied. The variables hold a reference to the object so when we pass an object into a method (or event), we are passing the reference even though the parameter is "by value" by default.

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

    Hi Tim!
    I have a question about the first event - TransactionsApprovedEvent. Can I replace this event with a Binding Source? I mean I could declare a new Binding Source and assign it to our transactions list from Account Class. Will it work?
    Of course, I would like thank you for this video. Your way of explaining C# is always awesome :)

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

    great video as always, can you explain the reference leak caused by events?

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

      Here you go: stackoverflow.com/a/4526840/733798

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

      @@IAmTimCorey thank you sir but i would rather that you consider making a video about this topic because you know how to explain things and make it easy to understand fankly i read a ton of articles but i couldn't get what i need especially the best practice when it comes to this problem

  • @franciscooliveira8585
    @franciscooliveira8585 11 месяцев назад

    Hello Tim! In this case, which one is the Publisher and which one is the Subscriber?
    Is the publisher in the UI or is it the one with the .Invoke() method? And the subscriber is the one which is called with the Invoke() method?

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

    Could you please give me an example of how to remove the events discussed in this tutorial ? to avoid memory leak and be more like a good citizen :)

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

      I will add it to the list. Thanks for the suggestion.

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

      not an expert but I usually do -= eventName which is how it is shown in UWP and Xamarin docs

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

    what is (object sender, EventArgs e)
    what's the problem in doing public event EventHandler OverdraftEvent; in Account.cs

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

    I've watched this twice now as I am blown away how easy it appears to be to update the UI as a result of a method running in a separate class. How does this compare to BeginInvoke for threadsafe UI updates? Is it suitable to have several event handlers running for UI update from classes- for a small app I'm guessing it's not too resource hungry. For example- if I had a Db checking class which ran on a timer to check for data changes every second - would an event handler be the best way forward. I am coming from a almost complete beginner position and someone who has struggled with UI updates from classes and thread safety. Big love for all your videos - really learning a lot!

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

      Events aren't really memory-hungry. There is nothing active really. They are just stored methods that get fired when they are called. An event that gets fired when an update to the database is discovered would definitely be a possible solution for your situation.

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

      That's great thanks Tim. I've also found out how important the ? Is when invoking the event. Form1 had stopped listening and it was throwing a null exception. Had I not known about that little gem I would still be screaming at my code. Really good videos - keep up the good work.

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

    Great work!

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

    Hi Tim!
    I highly appreciate you for providing us such a valuable content. I have a question about Events. For me it looks that everything you done by implementing events in this movie, may be achieved by implementing just appropiate plain functions. Is it true? Anyway, why really we should use events? I understand how they works, but i'm sure that i wouldn't be able to decide when use events, and when not in my code.

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

      Events allow you to act in a disconnected manner. Yes, you could just create a function but then the event caller would need to know about a method on the event receiver. That creates a tight coupling. Think about Windows Forms. When you click a button, you want something to happen, right? If that button click didn't fire an event but it called a method, how would you add your code later? Microsoft created the button. They would have to know which method(s) to call when they build the button but your methods weren't created until years later.

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

      @@IAmTimCorey great example

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

    What is The Advantage of Delegate and Events in C# Tim

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

      They are another tool in the toolbox.

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

    Thanks in a million.

    • @IAmTimCorey
      @IAmTimCorey  3 года назад +2

      You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. You're welcome. ...

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

    just like "WireUpForm()" in DashBoard.cs we can add a method whose actual purpose is clean up(deallocating the listeners to the events)

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

      We can do that. Typically it isn't needed though.

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

    at 25:01, what if we just write "public EventHandler RaiseTransactionApprovedEvent;"? The code seems to work, but what are the differences?

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

      That way exposes the EventHandler as a public field, which would allow it to be overwritten instead of just subscribed to. It is considered a dangerous practice: stackoverflow.com/a/46824847/733798 Good question.

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

      @@IAmTimCorey totally makes sense now! Thanks!

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

    Thank you for this :)

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

    Hello , lets say we have form1 with usercontrol1 that contain panel1 , in panel1 we have Panel2 with some buttons button1,button2...and also we have in Panel1 usercontrol2
    lets say i have some data manipulation in usrcontrol2 ...my question is how can i define an event in usercontrol2 that invoked in usercontrol 2, and consumed in usercontrol1 ,this event created in user control 2 need to changebackground color of button1 that is in user control1
    i tried many ways ,
    in your exemple you use a class that fire event and consumed by form1 or form 2 , but i want a user control that produce an event and the other consume it without classes ,so how to produce and event in usercontrol 2and keep user control 1 listining all the time to user control2 events
    please help me if you can