What are Delegates? (C# Basics, Lambda, Action, Func)

Поделиться
HTML-код
  • Опубликовано: 12 май 2024
  • 🌍 FREE C# Beginner Complete Course! • Learn C# Beginner FREE...
    🔴 Watch my Complete FREE Game Dev Course! 🌍 • Learn Unity Beginner/I...
    📝 C# Basics to Advanced Playlist • C# Basics to Advanced
    🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses​
    👍 Learn to make awesome games step-by-step from start to finish.
    🎮 Get my Steam Games unitycodemonkey.com/gamebundle
    ✅ Let's check out what are Delegates in C# and how they help us write cleaner and more modular code.
    Learn Unity in 17 MINUTES!
    • Learn Unity in 17 MINU...
    Learn C# BASICS in 10 MINUTES!
    • Learn C# BASICS in 10 ...
    What are Events? (C# Basics)
    • What are Events? (C# B...
    What are Delegates? (C# Basics, Lambda, Action, Func)
    • What are Delegates? (C...
    What are Interfaces? (C# Basics)
    • What are Interfaces? (...
    What are Generics? (C# Basics)
    • What are Generics? (C#...
    What are Loops? (C# Basics, for, while, do)
    • What are Loops? (C# Ba...
    Unity Tips in 10 MINUTES!
    • 12 MORE Unity Tips in ...
    Unity Basics for Beginners
    • Learn Unity in 17 MINU...
    Trigger an Action after some Time
    • Trigger an Action afte...
    Ability Bar in Unity (Swap Weapons/Items)
    • Ability Bar in Unity (...
    If you have any questions post them in the comments and I'll do my best to answer them.
    🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
    See you next time!
    📍 Support on Patreon / unitycodemonkey
    🤖 Join the Community Discord / discord
    📦 Grab the Game Bundle at unitycodemonkey.com/gameBundl...
    📝 Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
    #unitytutorial #unity3d #unity2d
    --------------------------------------------------------------------
    Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
    I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
    You can see my games at www.endlessloopstudios.com
    --------------------------------------------------------------------
    - Website: unitycodemonkey.com/
    - Twitter: / unitycodemonkey
    - Facebook: / unitycodemonkey

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

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 года назад +42

    🌍 FREE C# Beginner Complete Course! ruclips.net/video/pReR6Z9rK-o/видео.html
    🔴 Watch my Complete FREE Game Dev Course! 🌍 ruclips.net/video/AmGSEH7QcDg/видео.html
    📝 C# Basics to Advanced Playlist ruclips.net/p/PLzDRvYVwl53t2GGC4rV_AmH7vSvSqjVmz
    🌐 Have you found the videos Helpful and Valuable?
    ❤️ Get my Courses unitycodemonkey.com/courses or my Steam Games 🎮 unitycodemonkey.com/gamebundle
    Here's the highly requested Delegates video! Learn how to use this insanely powerful C# feature!

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

      Basic to advance full tutorial playlist link???

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

      Lol wtf yesterday we just started learning delegates and here I go. What a timing xD...

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

      You already made the best tutorials there are on events and delegates... Now please tackle interfaces and some practical game examples. Ps. What do you think about DI and Zenject in Unity? Is it worth a tutorial? Or a series? Does using it makes sense? Thanks for great stuff, for many things even if I already know and use them I still come here to get your angle on it.

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

      Right now this is only the second C# video but I plan to continue making them towards building a Beginner to Advanced C# Playlist.

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

      Yup Interfaces is definitely a topic I'd like to cover, I have a video coming soon on how to make a Modular Character Controller which uses Interfaces a lot in order to make the modules.
      Dependency Injection is something that I always keep in the back of my mind and it really helps me write cleaner more decoupled code.

  • @_Garm_
    @_Garm_ 4 года назад +256

    finally some one who explains how to use delegates, not how to create the delegates ! thank you :D

  • @Gers217
    @Gers217 4 года назад +198

    So delegates are like variables that store functions. Nice video. Waiting for more of this kind of topic

    • @ruffone8047
      @ruffone8047 4 года назад +28

      This is the beat long-handed description of the term "delegates" I have heard. I had trouble wrapping my head around the term, but I read this comment and it clicked.

    • @SkeleTonHammer
      @SkeleTonHammer 3 года назад +11

      I've used delegates before but never understood entirely how they work, and I always forget how to set them up, and what I can do with them, without looking up an example every time. This explanation just made it all click finally.

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

      Made it click, thank you

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

      Kind of like Lua Metatables then.

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

      3 years later this comment made delegates fully make sense

  • @77BeerGuy
    @77BeerGuy 2 года назад +69

    I'm still having a hard time wrapping my head around all the new terms, but this video has clarified so much about the delagate system. I especially liked how you broke down the delegate, then showed exactly what was going on behind the scene, followed by an iteration the syntax, examples, and another iteration. Now I can go back to the older videos and finally understand what you are writing! I feel like you just unlocked hours of your videos (an others who use variations of the other syntax) for me. Thanks!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +6

      I'm glad you found the video useful! Thanks!

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

      Same! finaly can understand previous videos! :D

  • @deadly_artist
    @deadly_artist 4 года назад +31

    Dude, I was always wondering what that weird looking code was supposed to do that some people used. glad i stumbled over this video explaining everything extremely understandable.

  • @JanZbedny
    @JanZbedny 3 года назад +38

    Excellent tutorial, thank you!

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

    Definitely highlights some extremely useful ways to implement delegates. Great video! Thanks 😊

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

    Interesting and well-made video on delegates, I have never really understood when to use them efficiently before working with APIs for the most part in my work, but I can definitely see the use of it now for games especially and will try to apply it to my own hobby games. Thank you for a great video!

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

    Awesome video, thank you for explaining "why we should use it" (not only "how") and providing the practical examples!

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

    Been trying to find information about Events all day. So many videos talked about delegates and never explained them simply for a beginner. You are the first to simplify it. Now I think I understand Delegates and how Events relate to them. You also showed great ways to use them so I can see their potential (and also how bad my beginner code is). Thanks.

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

    One of the best and clearest delegate explanation videos on RUclips. Great!

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

    Thank you very much! I've been working with delegates professionally for almost two years now but I couldn't do it right without referencing from previous work how to do it right, but after this video it is finally nailed down in my brain. You're the man!

  • @zenbrandon
    @zenbrandon 4 года назад +8

    I've just found your channel, and I can safely say you are easily my new favorite game dev channel. Keep up the awesome work, man!

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

    wow i was always struggling with delegates and events but you sir made them extremely easy ... thank you ... you are my best teacher

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

    after watching dozens of videos which includes some of yours also, this made everything clear. i mean every single detail is super clear now. thanks for your effort

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

    Probably the best tutorial i've followed on the subject thus far. Much appreciated!

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

    Not a game developer. I have learned the basics of all these concepts which I could not until now. Everything was mystery and now it seems so straight forward. Thanks..!!

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

    I'm just impressed about how you are able to explain something that was hard for me to understand in a few minutes only ! Thank you for this amazing tutorial ! I'm definitely subscribing to this channel, and going to watch the other tutorials about c sharp basics !

  • @chikato7106
    @chikato7106 4 года назад +36

    Sweet!! I'm loving these c# core tutorials.
    I have a Unity Engineer interview coming up and I feel like an imposter, so I hope I get it. Going through these videos help.

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

    Thank you so much! I've been struggling with those a lot. This made my understanding a little bit clearer

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

    Amazing tutorial! The demonstration of specific use cases really made it all click for me.

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

    This one, and the video about events, were really helpful. Thanks.

  • @Kokomo78
    @Kokomo78 3 года назад +6

    I checked almost 10 video tutorial to understand why I should use 'Delegate' but none of them gave me a clear understanding. But your tutorial, specifically the clip from 15:00 clear off all the clouds in my head. Now I know! Amazing clip! Thank you a lot.

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

    There have been very high quality, highly requested and very helpful videos during the past few weeks. Thank you so much for your effort.

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

      I personally don't really care about DOTS right now as there are many basic features that don't work in it right now and by the time dots is production ready, a lot of it will be different so I will have to relearn. I am personally just going to wait for it to be production ready.

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

      The DOTS core is meant to come out of Preview in 2-3 months so while it will take a long time for all the tools like UI, NavMesh, etc, to be converted into DOTS the base shouldn't really change significantly.

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

    I was following the concept but only really grasped it when you gave the examples at the end. thank you for this!

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

    Thank you! This made me understand delegates a lot more, and it gave me and idea on how to solve an issue I've been having.

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

    Awesome tutorial, immensely useful yet simple intuitive code-based examples. More power to you

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

    Thanks for giving a real-world game use case. That really helped me understand why learning this would be valuable.

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

    Great video and great job explaining it! I often use Action and Event delegates, and understand how they work through using them, but good to get a simple explanation from the ground up! I always got wierded out by lambdas but I think I get it now!!

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

    This is the best video for explaining these concepts! Great work mate and thanks

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

    Fantastic tutorial, simple and concise, great examples of use cases, thank you.

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

    Love your videos! I have been coding for 20 years....but still learn new stuff with your vids.

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

    Didn't know much about the Func types. The event videos are really awesome!

  • @eu.gabs.silva.
    @eu.gabs.silva. 3 года назад +1

    Like Always, your videos are just amazing. I watched the Basics Events one and now this....I really feel I'm leveling up. Thaaaaaaanks.

  • @kaminmiller
    @kaminmiller 9 месяцев назад +1

    I'm just getting started with Unity and C# and had been having troubles with Event Systems, and just 4 minutes in to this video it finally clicked. Thank you for this.

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

    I am really stunned with these tutorials!
    Thanks alot!

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

    this is soo in-depth, just what I needed, at the time I am increasing my C# knowledge and your tutorials and the unity official ones are the most helpful although your videos are more in-depth that's what I prefer, thanks for making these awesome videos.

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

    WOW!!! amazing video!!
    I've been learning unity for the alst 2 months and this open my mind,
    I'm pretty sure my code will improve a lot by knowing all this.
    Thank you! =D

  • @user-hz4tc2pf3x
    @user-hz4tc2pf3x 4 года назад +3

    This is crazy good. Bonus points for making your code look like a transformer from 3020

  • @erz3030
    @erz3030 4 года назад +7

    I dunno what it is about you, but you explain things in such a way where a thing I had a 50% grasp on previously, now make SO MUCH SENSE. I could watch 5 other videos on the subject, and this is the only one that I feel that got me to the point of understanding WHY/HOW it's implemented. Your examples are so simple but thorough!

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

    I never understood how to implement delegates. I watched dozens of videos. Now I understand. THANKS.

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

    "Mindblown" would describe precisely the way I felt when you showed the example about the attack types! Most games I've done so far are really, really simple projects but if I kept coding in the trivial way I would face obvious scalability issues in the future, well no more, thanks to this tutorial!

  • @Mikael._
    @Mikael._ 3 года назад +1

    Great tutorial, spent my weekend with no internet, and did some timer functions for my Tycoon game buildings.
    This is very interesting, will try to implement tonight cause there are diferent buildings using diferent timers and actions.
    Thanks ^^.

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

    Thank you so much for such an awesome and helpful tutorial!
    Also, important to note: We found out that although we cannot explicitly refer to and remove a lambda expressed function from the delegate, you can still clear out the delegate if necessary like this:
    public void RemoveAllCallbacks()
    {
    Delegate[] myDelegateList = MyDelegate.GetInvocationList();
    if (MyDelegate != null)
    {
    foreach (var method in MyDelegate)
    MyDelegate -= method as DelegateCall;
    }
    }
    This has helped up tremendously. Thank you so much!

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

    Very helpful video. These c# basics videos are very clear to understand and they have a lot of good information

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

    This is an awesome explanation for delegates, thanks so much.

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

    Excellent tutorial. Thanks to your video, I fully understand what are delegates, lambda expression, action, etc. Before I was afraid of these statements

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

    Subscribed. I’m a .Net engineer about a year and a half of experience. This video was super helpful.

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

    Thanks! The punch/sword attack example helped clarify for me why actions are actually useful

  • @phutureproof
    @phutureproof 3 месяца назад +1

    Man, I stumbled on your complete course, am halfway through it but I have my own ideas I keep trying and I gotta say every question I have, you have a video for, cheers!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 месяца назад

      Nice! Great job on applying your own ideas, that's how you truly learn! Keep at it!

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

    Never learnd so much in such short Time.Thx for the awesome Stuff.

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

    Great video! It sure made me understand how delegate works! Thank you so much!

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

    Great video, thanks for the detailed explanation each step of the way.

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

    Thank you! I have learned from this video what i have not from 100 books and other 100 videos. I am not a game developer, more on the web apps and database, but with you i can that i will start learning Unity ☺️

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

    Omg finally I found this tutorial! I never understood how lambda functions work...thx for the nice tutorial!🤗

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

    i wish this video was around before i learned from many many other videos. this explanation/showcase is simple and clean and the last 3ish minutes has to be the best way to showcase the practical uses of delegates i have ever seen. nothing worse then getting examples that make no sense and/or have no practical use.

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

      Thanks! I do try very hard to teach the theory and also show practical use cases.

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

      yeah the last part was really nice

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

    Great and simple video man, much better than reading the MS documentation!

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

    How did I not understand all these before your video? Amazing tutorial!

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

    one of the most useful c-sharp videos! thanks 👍🙏😊

  • @to-bt3le
    @to-bt3le 4 года назад +1

    Really helpful for beginners. Thank you ~

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

    Oh my goodness! I finally understand why delegates are useful. This is perhaps the only online resource that clearly explains what delegates are and how to practically use them - and it's free! You're amazing!

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

    man thank you for your videos, watching you its more fun than watching netflix

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

    Your channel is underrated you should be trending. The way you explain things is stunning. I am a self taught developer so its great to have a simple but top the point explanation. Great work.

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

    You're a godsend. Great programmer with great didactics.

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

    It is best video about C# delegates all over youtube. Thank you so much for you work! My head was exploding because of delegates, but now I understand a lot

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

    Amazing tutorial, thank you so much!

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

    Never learned so much in "Intro", thanks!

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

    Thank you, i am a bit of a noob when it comes to programming so this advanced stuff is great.
    Thank you for these.

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

      Some words of wisdom from one learning programmer to another, there is no such thing as "advanced". There are only tools, and the more tools you know how to use, but better stuff you can build with those tools. It can be tricky and confusing sometimes because you have to wrap your mind around new concepts. But don't trick yourself into thinking it's too complicated to understand and then put off learning it. 99% of programming is easy to understand once you know how the language components work. The other 1% is knowing how to make clean (not sloppy) code.

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

      @@Andrew90046zero Right, I will mind those words of wisdom,Thanks.

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

    Awesome explanation! Well done, thanks a lot.

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

    Another splendid one, thanks!

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

    Beautiful Tutorial, Helped me a LOT :)

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

    So back to delegates, this stuff has finally sunk in. It's only my third time using them so it's not like it took me 3 months to learn it but I thought I'd say thanks AGAIN because this should really help me get through your Unity NetCode tutorials. Thanks a million CM.

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

      Heh it does take a while to click but when it does it's another excellent tool in your toolbox!

  • @seanloughran6714
    @seanloughran6714 6 месяцев назад

    I am writing a new class for Marching Cubes, and I was going to abstract out the data retrieval and culling of data and colors outside of the Marching Cubes algorithm using Delegates. I looked at the ObjectPool from UNITY as a reference, as they do it very similarly to how I wanted to. I was immediately confused by Delegate vs Action vs Func and within 10mins you explained them all and I am empowered to move forward! Thanks as always for these amazing videos!

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

    This flew way above my head

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

    You are the best tutor available on RUclips. I understood a lot on Delegates watching your explaination.

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

    You helped me alot with that content, thanks!

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

    I am starting to love coding after watching your tutorials.
    Thanks CodeMonkey!

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

    What a great video, thanks for the real world examples.

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

    This was so amazing!

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

    I love your tutorials so much

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

    thanks man this was really usefull and it made my works much easier .. keep going well done

  • @abtinb.f691
    @abtinb.f691 Год назад

    thanks a lot, it helped me understand the core idea of Delegates. Great examples by the way.

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

    Really Useful explaination .Thanks alot .It's good to see code in Action

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

    A very good and simple explanation . thank you

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

    It is incredible how fast you type.

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

    Lovely explanation. Thank you

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

    thanks for the tutorial! as a java developer this is a whole new concept to me and it was explained very good : )

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

    Very very clean explanation, this was beautiful, congrats (Y)

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

    Didn't even know what a delegate was before this video. Thank you so much for providing us with these awsome tutorials

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

    Wow, great explanation and examples, thank you such much, I'm subscribing

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

    Oh, this seems really useful! Thank you!

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

    You're a genius teacher, thank you!

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

    Finally understood the concept! Thanks for making such awesome videos!! Love from India!!!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  11 месяцев назад +1

      I'm glad the video helped you! Thanks!

  • @glasgood9907
    @glasgood9907 6 месяцев назад

    Fantastic use case examples.

  • @3isr3g3n
    @3isr3g3n 25 дней назад

    Mate this is gold i'm gonna recommend it to my former game design class teacher

  • @jean-michel.houbre
    @jean-michel.houbre 4 года назад

    I love the delegates even more!

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

    Best delegate class on youtube! Thank you! I just can't understand how this can have 7 dislikes...

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

    your courses are really nice

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

    Amazing tutorials i even understand Generic Classes.

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

    When i see another tutorial. I can know what is delegates and i don’t know how to use them. Your example explain me a lot thank you.