Delegates in C# - A practical demonstration, including Action and Func

Share
Embed
  • Published on May 28, 2018
  • Delegates in C# are really powerful but most people don't know how to use them effectively, if at all. Today I am going to show you what delegates are, how to use them, why they are useful, and really how to take your code to the next level. Along the way, I will cover the special types of delegates named Func and Action. Now if all of these new words seem intimidating, don't worry. This topic is actually really simple at its foundation. Yes, you can do some complex things with delegates but an actual delegate is absolutely simple.
    Source Code: leadmagnets.app/?Resource=DelegatesInCSharp
    Patreon: patreon.com/IAmTimCorey
    Newsletter signup: signup.iamtimcorey.com/

Comments • 199

  • Desi Trump
    Desi Trump 11 hours ago

    delegates are themselves types and need to be declared outside class as far as I know. Is that correct?

    • Desi Trump
      Desi Trump 4 hours ago

      @IAmTimCorey ok, I've recently got job as an MVC developer. Do you have any videos where you teach developing complete demo MVC projects from scratch?

    • IAmTimCorey
      IAmTimCorey  4 hours ago

      They do not need to be declared outside of a class but they are reference types.

  • Franco Minucci
    Franco Minucci 4 days ago

    Are delegate just function pointers with a specified signature? I don't really understand your explanation :(

    • IAmTimCorey
      IAmTimCorey  2 days ago

      Basically. C# does not have function pointers. The equivalent is a Delegate, but the difference is that a delegate has a strongly-typed signature.

  • Andrei Luca
    Andrei Luca 6 days ago

    Hi Tim. It's been five years since I started working as a developer, yet I still find your videos instructive. There are things I thought I understood, but actually didn't and some aspects that were always foggy for me and that now are coming to light. Thanks for your work, your ability to explain sth you've understood is outstanding. I know a lot of developers that really know what they're doing, but when it comes to explain it to someone else, they fail miserably. Thanks again Tim.

  • Anand Mishra
    Anand Mishra 11 days ago +2

    believe me i am a beginner , and this video is so confusing

    • IAmTimCorey
      IAmTimCorey  9 days ago +2

      This isn't a beginner video. It is a video for learning delegates for the first time but delegates are an advanced topic. If you want to learn C# in order, check out my Foundation in C# course series at www.iamtimcorey.com/p/complete-foundation-in-c-course-series It will start you from the beginning and take you through to a place where you could be a junior or even mid-level C# developer.

  • Bahawal TV
    Bahawal TV 16 days ago +2

    Most of the videos does not explain the concept, and they just start coding.
    Delegates provide ability to pass methods as parameters to other methods. So that other methods can execute them. In Javascript functions are objects. So passing a function as parameter to other methods is not a problem. But in C#, you must add the function reference to a delegate object, and then it can be passed to another method, which can execute it as and when needed. Most popular use of delegates is in implementing callback methods or event handlers. C# EVENTS use delegate internally to implement events and event handlers.
    The PUBLISHER class declares a delegate, and then an event which uses the delegate internally. Then raises the event as and when needed.
    The SUBSCRIBER class subscribes to the event of publisher. Internally, it just adds the EventHandler method reference to the delegate of SUBSCRIBER. That is the whole story.

    • IAmTimCorey
      IAmTimCorey  16 days ago +1

      I’m confused. Are you saying my video did not explain that or that other videos do not explain that but I did?

  • Vinay Palaksha
    Vinay Palaksha Month ago

    Tim, syntax for creating an instance of a delegate is same as that for class, so I'm curious to know is delegate really a class behind the scenes?

    • J Lito Delcid
      J Lito Delcid 6 days ago

      @Vinay Palaksha yes, but as Bahawal says, you can't 'instantiate' the same way as if you're working with common classes. You can consider that delegates have not the characteristics to be considered classes.

    • Vinay Palaksha
      Vinay Palaksha 6 days ago

      @J Lito Delcid but class is also a reference type right?

    • J Lito Delcid
      J Lito Delcid 6 days ago +1

      Not exactly, delegates are more like reference type 'variables'

    • Bahawal TV
      Bahawal TV 16 days ago +1

      There is a delegate class. But you can't instantiate it or extend it. It can only be used through DELEGATE keyword.

    • Vinay Palaksha
      Vinay Palaksha 28 days ago

      Tim,That is ok

  • cod4Rlp
    cod4Rlp Month ago +2

    man you are wholesome, asking is people are financially able

    • IAmTimCorey
      IAmTimCorey  Month ago

      Thank you. My primary purpose is to help people. I definitely don't want people spending more than they should out of a feeling of obligation.

  • faizal vasaya
    faizal vasaya Month ago +3

    - The best explanation of Delegate.
    - The best part of this video is that the focus is on details and that is where the devil lies.
    - Keep up the good work Tim Corey. :)

  • Gopi R
    Gopi R Month ago

    This reminds me of the AddressOf operator in VB6, which I implemented a few times. It also reminds me of how we used to declare and raise events in VB6. Good memories.

    • IAmTimCorey
      IAmTimCorey  Month ago

      Yeah, delegates are really close to events (events are a type of delegate).

  • Kevin Wegrowski
    Kevin Wegrowski 2 months ago +2

    It just occurred to me how much using delegates in this manner reminds me of the Strategy Pattern -- could you explain why you would use one over the other?

    • Kevin Wegrowski
      Kevin Wegrowski 2 months ago +2

      @IAmTimCorey Right - I was thinking more of the"standard" implementation (interfaces and classes) vs using delegates. Anywho, this is something I can just dig into - no need to waste your time haha.
      Fantastic videos by the way - almost done with your C# start to finish series, and I've definitely picked up a handful of things I hadn't known or thought of before. Would have been 100% worth the $70 - I'll know for my next C# curiosity :)

    • IAmTimCorey
      IAmTimCorey  2 months ago +1

      Delegates can be used to implement the strategy pattern. The pattern is just a concept. Delegates are one way to carry out that concept.

  • Shayak Das
    Shayak Das 2 months ago

    That's an excellent way of teaching. It's much easier to understand like this instead of reading the concept in book. :)

    • IAmTimCorey
      IAmTimCorey  2 months ago +1

      I am glad you are finding it enjoyable.

  • Peter John Paul Tactacan

    I remember your video about the concept of interface so much that I could relate it with delegates.

  • Learn With Doc
    Learn With Doc 2 months ago

    Wonderful lecture and very clear in your teaching approach - really appreciate your talent to teach

  • BoJiun Chen
    BoJiun Chen 2 months ago +1

    THANK YOU!

  • Jeremy Flowers
    Jeremy Flowers 2 months ago

    odd delegate name MentionDiscount - when really it's the Total

    • IAmTimCorey
      IAmTimCorey  2 months ago

      The job of MentionDiscount is to tell the user what the sub-total of the order is. The key is mention, not discount. Maybe it could be mentionSubTotal.

  • DeepSyntax
    DeepSyntax 3 months ago +7

    I don't think people realize the value of these videos.

    • Davey Lad
      Davey Lad 2 months ago

      Same here, I watch all his vids.

    • Bence Juhász
      Bence Juhász 2 months ago

      I think the same! Thank you Tim for this channel, unique in C# I've ever found!

    • IAmTimCorey
      IAmTimCorey  3 months ago +2

      I'm glad you see them as valuable.

  • Guy Provost
    Guy Provost 3 months ago +1

    Just want to let you know that if you go to around 50 minutes in the video, you seem to repeat a section where you present the startup code, like if you notice that you already had a private static void already written. I think you forgot to edit it out!

    Just want to let you know, because looking at the quality of your videos, it shows that you put a lot of time in it and that I put the time to watch it very carefully!

    Great... Great content, thanks for sharing!

    • IAmTimCorey
      IAmTimCorey  3 months ago +1

      That could be and I just missed it when doing my edits. Glad you enjoyed it anyway.

  • Phani Raghavendra Prasad

    Thank U very much! Awesome example and explanation.

  • Russell Kemmit
    Russell Kemmit 4 months ago +6

    No BS, I watched this video 5 days ago and used my knowledge to answer an in person interview question today!! Thanks Corey!

    • IAmTimCorey
      IAmTimCorey  4 months ago +1

      Awesome! Good luck on landing the job. Glad I could help.

  • Russell Kemmit
    Russell Kemmit 4 months ago +3

    You are my new best friend!!!!

  • 旺旺
    旺旺 4 months ago

    thanks so much, Tim.
    Majestic!

  • Steven K James
    Steven K James 4 months ago

    cool

  • Alistair Halpern
    Alistair Halpern 4 months ago

    Why did you put the delegate inside the class rather than the more general namespace? Can a delegate be accessed from anywhere in a solution meaning it has unlimited scope. Did you need to declare references from the UI project to the demo library?

    • IAmTimCorey
      IAmTimCorey  4 months ago +2

      (I'll share what happens practically - the theory is a bit more complex) A delegate shares an access point to the code you point at so that the method you send it to can call the code you send it. You don't need to give the caller access to the namespace or library where the code it is calling lives. Remember an event is a type of delegate. For events, we tell it which method to call internally even if the event is fired in an external class. The reason this works is because we basically pass a message (with the associated data) to every indicated location. At that location, the correct method gets called.

  • Frank Thomas
    Frank Thomas 5 months ago

    Hey Tim, do you have a course that discusses this whole application build from start to finish? I've got a fair bit of c# experience, but see that there are a lot of things I can still learn from yourself!

    • Frank Thomas
      Frank Thomas 5 months ago

      @IAmTimCorey Hey Tim, sorry if you do see the previous comment I left here but for some reason I don't see it anymore. Question for you, the big reason I'm interested is because I really want to learn more about delegates/events and also proper thread/task handling in c#. Does this course you mentioned above talk about these topics in depth too?

    • Frank Thomas
      Frank Thomas 5 months ago

      @IAmTimCorey Hey Tim, good to know. I do know a lot about c# in the mvc realm, but I"m interested in learning higher topics like the video content plus better programming using tasks/threads.

    • IAmTimCorey
      IAmTimCorey  5 months ago

      This particular application? No. However, I do have a couple start to finish courses that build an entire application. My C# Application from Start to Finish course does that, plus it has two add-on courses for switching out the WinForm UI with WPF and ASP.NET MVC. I also have a smaller SQLite course that builds a complete application.

  • Al-Omda Ahmed
    Al-Omda Ahmed 5 months ago

    thanks a lot bro
    its a great tutorial helped me a lot
    wish you all the luck
    big fan from Gaza Palestine

    • Al-Omda Ahmed
      Al-Omda Ahmed 5 months ago

      @IAmTimCorey
      i wonder if you cover MVC request life cycle in one of your videos

    • IAmTimCorey
      IAmTimCorey  5 months ago +1

      I'm glad it was so helpful.

  • Jorn Van der Wal
    Jorn Van der Wal 5 months ago +1

    15:33 reported sir

    • IAmTimCorey
      IAmTimCorey  5 months ago

      I'm not sure what you mean. Edit: ah, lol.

  • Vandel Jason Strypper
    Vandel Jason Strypper 5 months ago

    I err... confused 😕 should I learn this before or after lambda expression ?
    but still better than other

    • Vandel Jason Strypper
      Vandel Jason Strypper 5 months ago

      @IAmTimCorey Wait hold up
      LINQ ? I thought Lamda was made to replace LINQ in sorting data right ?

    • IAmTimCorey
      IAmTimCorey  5 months ago +4

      This uses lambda expressions so you should know how to use them (at least the basics) first. My Linq 101 video explains how they work: thexvid.com/video/yClSNQdVD7g/video.html

  • COOLBIAN57
    COOLBIAN57 6 months ago +3

    Thanks Tim, I'm a new(ish, lol) computer science bachelor and finding your videos the very best of the best for reviewing these concepts.

    • IAmTimCorey
      IAmTimCorey  6 months ago

      I am glad you are finding these videos helpful.

  • TOABA OMAR
    TOABA OMAR 7 months ago

    great video as always could please you make about reflection the how to use delegate to improve the performance of an app that uses reflection and thanks again for your great videos

    • IAmTimCorey
      IAmTimCorey  7 months ago +2

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

  • comsci
    comsci 7 months ago +1

    dude just get to delegates please. you are teaching us how to debug and all the other stuff. get to the point.

    • Prime v_x
      Prime v_x 6 months ago

      @IAmTimCorey You are right off course about providing context. However, comsci is not wrong either, you go of into these little tiny tangents about format specifiers and tuples. And short as these might be they completely distract me from the core lesson which is Delegates.

    • Maciej K
      Maciej K 7 months ago

      I for one enjoy the additional context. The videos are longer, but more comprehensible.

    • Muhanad Ahmad
      Muhanad Ahmad 7 months ago +2

      Go watch the other videos of 5 min and understand how delegate is a pointer of a function with no actual knowledge.....good luck

    • IAmTimCorey
      IAmTimCorey  7 months ago +14

      The point is that delegates don't live in a vacuum. Learning pieces of coding is useless if you don't understand how and when to use them and how they fit in a bigger picture.

  • K4MR4N1UK123
    K4MR4N1UK123 8 months ago

    Just use the bloody pointers.

  • fans ban
    fans ban 8 months ago

    SIir Why we Use Delegates Why The are required?

    • fans ban
      fans ban 8 months ago

      @William Gingras Thanks

    • William Gingras
      William Gingras 8 months ago

      @fans ban In the first example, you can pass a private function of an object to another class and "access" it, instead of making it public

    • fans ban
      fans ban 8 months ago

      @IAmTimCorey Sir Plz Tell Some Comman Advantages

    • IAmTimCorey
      IAmTimCorey  8 months ago +1

      The video talks you through some options of when they are useful. I can't tell you every case, since there are so many possibilities.

  • fans ban
    fans ban 8 months ago

    Sir i Have a Question What is Difference Between Linq and PLinq

    • fans ban
      fans ban 8 months ago +1

      Thanks Sir I Had a very good Concept about it now after visiting to your Given website linq and By Seeing The Comment of Yours Thanks!

    • IAmTimCorey
      IAmTimCorey  8 months ago

      The "p"? Sorry, easy joke. Plinq is parallel linq, meaning the operations happen in parallel. There are limited uses for it, but when you do have a use for it, it is really helpful. Here is more info: docs.microsoft.com/en-us/dotnet/standard/parallel-programming/introduction-to-plinq

  • Riyaan N
    Riyaan N 8 months ago

    Hi Tim, Thanks for this video. I could see mentionDiscount delegate return type is 'void' and Func CalculateDiscountedTotal return type is 'decimal' , so you have return calculateDiscountedTotal , but what should be done when delegate mentionDiscount also returns something. you cannot have two return statements right?

    • Riyaan N
      Riyaan N 8 months ago

      @IAmTimCorey thanks a lot

    • IAmTimCorey
      IAmTimCorey  8 months ago

      They can both return something because each is a separate call. The resulting method could use both return values to then return an aggregate (if applicable). Also, you can return more than one thing if you would like. It is called a Tuple.

  • Layarion
    Layarion 8 months ago

    Ok watched the whole video. *question* naming conventions for delegates? Would it be fine if I put Delegate at the end of the name of each custom delegate i make?
    just on the surface of things, to me it seems like someone could get dizzy faster than with other things if a delegate has a bad name.

    • IAmTimCorey
      IAmTimCorey  8 months ago

      I don't see any major problems with doing that. It describes what it is and there isn't a time when a delegate isn't a delegate. Go for it.

  • Layarion
    Layarion 8 months ago

    ohhh so maybe this is how I can have a library display information to the user without having a bunch of strings that the end app has to search out to display.

    • Layarion
      Layarion 8 months ago

      @IAmTimCorey i don't know, but i'll look into it thanks. just a noob creating a helper tool for a video game that uses xml modding.

    • IAmTimCorey
      IAmTimCorey  8 months ago

      Can you create your own markdown-style format that you then parse on the other end? Something like "This is normal text. This is green text This is normal text again"

    • Layarion
      Layarion 8 months ago

      @IAmTimCorey well i wish ... you know how \n is a new line? well i wish i could color the text with something similar, because otherwise i have to have the UI do it...which means then i need to keep the segment of text i want colored, in it's own space/variable.

    • IAmTimCorey
      IAmTimCorey  8 months ago

      Isn't it fun when you find a new feature to play with?

  • Antonio
    Antonio 9 months ago

    @IAmTimCorey, Question please. Let's say we have classes: ClassA and ClassB. Basically a Delegate is just a pipeline or "chain" which points to a method / custom method. For example if you declare a delegate in ClassA and there you have a method that takes a delegate as a parameter, you can call that method from ClassB or any location in the application as long as it's visible and pass a parameter that matches the signature of the Delegate in ClassA. Then the logic of the method of ClassA will get executed normally and at some point inside of the method body of ClassA you can call that parameter ( which is a method ), the delegate declared in ClassA will be chained to the passed method and the body of the method which resides in ClassB will be executed. That's why they are assimilated with Function Pointers from C++.

    • Antonio
      Antonio 9 months ago

      @IAmTimCorey - if all the nonsense I've written above is a delegate, more or less :-). At least that's how I understood it - I'm not so good at explanations when I do not fully understand things.

    • IAmTimCorey
      IAmTimCorey  9 months ago +2

      I'm not sure what your question is.

  • Stephen DeCaro
    Stephen DeCaro 9 months ago

    This has been so helpful! Thank you!

  • Michael Eichner
    Michael Eichner 9 months ago

    Great video as usual.
    I have two questions.
    1. I noticed that in the console example methods like SubTotalAlert were static, but in the winforms example they weren’t static. Am I correct that the method being static or not static has nothing to do with the delegates? In other words the console example didn’t need static methods?
    2. Given the following scenario:
    I have several customers and hope to keep adding customers. Most calculate the discount in their shopping carts the same way. A few have their own custom calculations.
    Question: Would I be better off having my Shopping Cart class, use a delegate, an interface or inheritance where the Shopping Cart class is the base class that has a method called CalculateDiscount, and then override that method in customer specific Shopping Cart classes?
    Thanks

    • Michael Eichner
      Michael Eichner 9 months ago +1

      IAmTimCorey Thanks for the fast response and opening up the world of delegates in such a clear manner.

    • IAmTimCorey
      IAmTimCorey  9 months ago +2

      Yes, static has nothing to do with the delegate (how it works). WinForms are in a class instance already. Console apps start from a static class. You can still use class instances in a Console app but I didn't bother.

      That really depends on your scenario but it sounds like an inheritance situation, where you override the method in certain circumstances.

  • mrmcbuggles
    mrmcbuggles 9 months ago

    Hello, Do you have any videos on dynamic expression trees with generics, Expression.Call, etc.? Edit: Should have said, to make dynamic SQL statements beyond the simple .Equal or the like. Things like "Where" and "Contains."

    • mrmcbuggles
      mrmcbuggles 9 months ago

      @IAmTimCorey I understand. FWIW, if you do get further requests, I am speaking about Dynamic SQL based upon Expression Trees in Linq. Maybe Dynamic Linq Expressions is the best way to say it. Since we can't use strings to change the Linq Expression (like in .Where, .Contains, etc.), we have to use Expression Trees. It's easy enough, but it gets complicated when the stock .Equal and such are not what you need and you have to use] a .Where. There is a Dynamic Linq library from way back that Scott Guthrie introduced, but that is not what I am mentioning here. In any case, thanks for the videos.

    • IAmTimCorey
      IAmTimCorey  9 months ago +2

      I do not have a video on dynamic expression trees. I have found those to be used so little as to almost be unnecessary. My philosophy is to not create videos on topics that are very small and probably should stay that way. If I create a video on the topic, I'm almost encouraging people to use it. All that to say that I'll probably not cover this topic in a video (but thanks for asking).

      As for dynamic SQL, it depends on what you mean. LINQ performs SQL-type operations (filtering, sorting, etc.) and I do have a video on that. Creating dynamic SQL statements themselves, though, is not something I've covered.

  • Insomnia
    Insomnia 10 months ago

    Hey Tim! Great video as always. I do have a question which has always kind of haunted me. Since I use WPF and typically have multiple windows; sometimes I need to update the main GUI from say a settings window. A setting could be changed which affects the main GUI and then it needs to update. Would it be better to use a delegate which I guess could probably be passed into the constructor of the window? Or would it be better to fire an event off saying some list has updated or whatever and the main GUI could listen for that?
    This interaction between windows in WPF has always confused me and I've seen people pass an instance of their main viewmodel via "this" and I do that now but it feels janky and just wrong when you go through the entire WPF process and then do some dirty trick like that. I mean idk what is right and have never found a good solution online so what do you think?

    • IAmTimCorey
      IAmTimCorey  10 months ago

      If you are using MVVM in WPF, you would use the event aggregator. If not, and if this is common, you could create your own. Otherwise, passing around a class instance is actually a good idea. It is making use of the benefits of OOP.

  • Pieter W
    Pieter W 10 months ago +1

    Great explanation. Not to fast and taking me step by step. Thanks. Used lamba expressions for a while now but its always nice to know what they do

  • semen083
    semen083 10 months ago +1

    In my opinion tbe best profit of using Func and Action it is use in Expression. The best way of delegation of method implementation it is using Interfaces.

    • IAmTimCorey
      IAmTimCorey  10 months ago

      Well, there are a lot of uses for each. The key is to limit yourself to choosing the best tool for the job, just just the cool one.

  • godfathermikal
    godfathermikal 11 months ago +2

    This video is awesome! Thank you.
    Do you did pluralsight courses?

    • IAmTimCorey
      IAmTimCorey  11 months ago

      I have not done a Pluralsight course (yet - no plans at this point either). I do have my own site ( IAmTimCorey.com ) where I sell courses but I haven't partnered with a company like that to sell my content as part of a subscription.

  • Marta Krzyk
    Marta Krzyk 11 months ago +2

    Awesome video!

  • Sanwal Chaudhry
    Sanwal Chaudhry 11 months ago +2

    awesome explanation... I will recommend this video to every beginner programmer.

  • Wttftyh Gytyf
    Wttftyh Gytyf Year ago +2

    Came here for SOLID but checking your versions on other topics too haha.

  • quicktastic
    quicktastic Year ago +1

    Although delegates are not that complicated in general. It does seem to be a concept that doesn't lend itself well to explanation. Mainly because of the seemingly disconnected entities being created which leads to a lot of "what did he just do? where did he put that?". You do it about as well as it can be done. Nice video.

  • UltimateYT
    UltimateYT Year ago

    1:50

  • Rascovici Bogdan
    Rascovici Bogdan Year ago +1

    great explanation ! keep up the good work :D

  • Khuraijam Upendrajit

    Thank you sir

  • dowdag
    dowdag Year ago +2

    Thanks, However still confused, maybe another IAmTimCorey video on just Delegates and Events would be
    helpful to jr. net developers :)

    • IAmTimCorey
      IAmTimCorey  Year ago +3

      They will be in a start to finish series or two. In the meantime, practice what you see in the videos. It will help, even if you don't understand everything.

  • Huggabearskij
    Huggabearskij Year ago +8

    I'm so incredibly grateful that people like Tim exists that takes the time to show how it actually works so I don't have to waste my life at stack overflows 8 year old outdated answers. Thanks!

  • Gil Cooli
    Gil Cooli Year ago +2

    Hi Tim. I hope you feel better soon. I miss your lessons and wish you a good health.

    • IAmTimCorey
      IAmTimCorey  Year ago +5

      I'm finally getting better. New videos are coming soon.

  • Shawn Kanyer
    Shawn Kanyer Year ago

    Will we be seeing more videos? Also, do you ever put methods in the models of the library to run the SqlConnector commands? It seems like it would make sense to have get and save methods on the library classes.

    • IAmTimCorey
      IAmTimCorey  Year ago +2

      I'm going to be putting out new videos soon. I've had some health issues (I'll be doing a video on this too) that have taken a lot out of me. I'm starting to recover now and I can't wait to start getting videos on here again.

      As for your other question, I'm not sure I'm visualizing what you want to do here. Are you saying to put a get and save method on the model itself? The problem with that would be if you ever wanted to change database types. You would need to change every model.

  • Twenty Twenty
    Twenty Twenty Year ago +1

    Good voice, pace, etc., and very glad you are here.
    This video should be reshot posthaste. The use of excruciatingly awkward method names and nonsensical calculations make it hard to track and remember what one has learned.
    While I got, because of previous experience, the gist of the advantages of delegate usage (console vs. WinForm output is a good example) and delegate usage is an elevated (and intrinsically cryptic-looking) textbookish technique, the user may ask, "Rather than the oddball gymnastics of delegates, why not use an abundantly clear IF statement that branches on console or UI?"
    The takeaway on FUNC and ACTION was lost. Why would I bother with these? What are they wrapping? Is Santa still coming? Totally lost.

    • Twenty Twenty
      Twenty Twenty Year ago

      P.S. I listened again to the FUNC and ACTION portion, and I think I get it now. First run through, the naming was throwing me off. Rinse, lather, repeat. :-)

    • Twenty Twenty
      Twenty Twenty Year ago

      Yikes. Well, so much for formatting. :-)

    • IAmTimCorey
      IAmTimCorey  Year ago +1

      The issue of delegates is who creates the method. The examples I gave with WinForm vs Console illustrate it but they would not be solved with a simple if statement. If you tried an if statement, it would work until you tried to use the library in ASP.NET MVC. Then you would have to update the library and redistribute it again with new logic for that UI. Then you would have to do it again for ASP.NET Core or Xamarin or any other UI. By using a delegate, we can put in the UI logic into a class library that does not change. When we add the UI, we add the UI logic. That allows us to follow the Open Closed Principle (OCP) and it allows us to more easily maintain our library and our applications.

  • tanu1215
    tanu1215 Year ago

    Thanks for the video, Tim! I'd appreciate some videos on low level stuff. How the compiler works, for example.

    • IAmTimCorey
      IAmTimCorey  Year ago +1

      That's an interesting idea but it is probably a bit outside of the scope of my channel though.

  • mattd390
    mattd390 Year ago

    Are you ok, Tim??

    • mattd390
      mattd390 Year ago +1

      IAmTimCorey get well, buddy!

    • IAmTimCorey
      IAmTimCorey  Year ago +5

      I let my mailing list know and I'm planning on doing a small piece on it in my next video (hopefully this Monday) but I'm recovering. I had a heart issue that took me down and has been difficult to recover from. My heart is healthy but a virus is attacking the lining so I'm weak and have to watch what I do. I'm on the road to recovery but it is taking time.

  • offichat
    offichat Year ago

    It would be really helpful if you could make a video about abstract classes. So far you have only covered interfaces and it would help to clear the confusion when it's better to use an interface or an abstract class.

    • IAmTimCorey
      IAmTimCorey  Year ago +1

      That is on the schedule to do soon. Good suggestion.

  • Int Er
    Int Er Year ago

    Do you have videos you can make on working with APIs in .NET/C#

    • IAmTimCorey
      IAmTimCorey  Year ago

      Not yet. I do have a video on making an API but not yet with working with them. Soon though.