C# Delegates, Lambda Expressions, Anonymous Methods, Actions, Func... The Difference Between

  Рет қаралды 19,832

AngelSix

AngelSix

6 жыл бұрын

With all of the different names, types and styles all floating around, I aim to break down the confusion between delegates, anonymous methods, lambda expressions, actions and functions as well as show how they are all used in a few scenarios.
Source Code: github.com/angelsix/youtube/t...

Пікірлер: 95
@vinuhosanagar1
@vinuhosanagar1 6 жыл бұрын
Thanks much bro. You are investing your time for us. May God bless you and your family with all happiness :)
@AngelSix
@AngelSix 6 жыл бұрын
Your welcome :)
@rylanwassem4197
@rylanwassem4197 2 жыл бұрын
I'm really impressed with how informationally dense this tutorial is. Keep up the good work!
@adamodimattia
@adamodimattia 5 жыл бұрын
Better than any paid course I've taken. Finally some real explanation!!! It is the best channel for C# and not only. Thank you!!!
@AngelSix
@AngelSix 5 жыл бұрын
Glad I could help :)
@chiefxtrc
@chiefxtrc 4 жыл бұрын
why doesn't anybody else seem to be able to explain this topic clearly like this? great video
@AngelSix
@AngelSix 4 жыл бұрын
Thanks
@kieranp5780
@kieranp5780 5 жыл бұрын
yo you literaly solved some of the questions i didnt even have yet XD, amazing video and great explanation, I have been looking all over youtube for a straight-to-the-point understandable explanation like this. Subscribed :)
@kopilkaiser8991
@kopilkaiser8991 Жыл бұрын
You are the best. Being able to deliver information best way possible.
@sokinooo
@sokinooo 4 жыл бұрын
Awesome tutorial Luke! just binge watched nearly all of your videos. Respect for all of the work you put into making those vids
@AngelSix
@AngelSix 4 жыл бұрын
Thanks. Wow thats a lot of hours you are watching :)
@sokinooo
@sokinooo 4 жыл бұрын
@@AngelSix Yes indeed, a lot of it clicked for me just now after watching your videos. Looking forward for the follow-ups on the C# master class!
@nrich4704
@nrich4704 6 жыл бұрын
That was a beauty. I've been struggling with all the items discussed. The way in which you have laid out the progression of invention of these items is wonderful. Thx.
@AngelSix
@AngelSix 6 жыл бұрын
Thanks. Glad I explained it clear
@SuperChickenBurritos
@SuperChickenBurritos 5 жыл бұрын
Amazing video man! As a software dev student, I find your vids pretty useful on the side! Cheers!
@ozmuzo739
@ozmuzo739 5 жыл бұрын
You are absolutely brilliant mate!!! So hard to find someone who actually explains the process rather than just spitting jargon. Great job and thank you!
@AngelSix
@AngelSix 5 жыл бұрын
Your welcome, glad you like the vids :)
@steveymcneckbeard
@steveymcneckbeard 5 жыл бұрын
4.8k views?! So glad I found this channel you are a great teacher. Thank you for this
@AngelSix
@AngelSix 5 жыл бұрын
Your welcome :) Hope you like my videos
@umairsaeed5055
@umairsaeed5055 4 жыл бұрын
Trouty McSquire now 9.3k views
@AJ-xd2wt
@AJ-xd2wt 3 жыл бұрын
Am currently studying cSharp at a school in Sweden and i just could not understand this, your video explains it so well and makes it all so simple an infant would understand it. Thank you sir, definitely worth a sub.
@randomCADstuff
@randomCADstuff 2 жыл бұрын
Your example of a Delegate as a way to pass a method into another method... in basically one sentence clears up so much confusion. To date (including about 5 different books and at least 3 hours worth of tutorials) I've only seen Delegates used in very redundant examples with no real explanation of their true purpose or practicality. Your tutorials/explanations are the best. Not just this one. And believe me I've viewed A LOT of tutorials. Thanks for all your hard work!!
@AngelSix
@AngelSix 2 жыл бұрын
Thanks that's great to know
@sora-senpai
@sora-senpai 6 жыл бұрын
Thank you so much, I was waiting for this video so I can continue with the WPF course.
@AngelSix
@AngelSix 6 жыл бұрын
카림사부 no problem
@missionyoungblood
@missionyoungblood Жыл бұрын
Defo one of the best dev channels out there!!!!
@baselpro5228
@baselpro5228 2 жыл бұрын
Your knowledge just outstanding. Thanks for the videos explaining C# and Multithreading
@TheAlphaGeko
@TheAlphaGeko 6 жыл бұрын
Yay a new video thanks ! You explain things very well and I'm learning a lot
@AngelSix
@AngelSix 6 жыл бұрын
Ovisionik thanks
@ShanthiStudios
@ShanthiStudios 6 жыл бұрын
You are an excellent teacher! You should become a PluralSight author. Thank you so much for doing the video series. You have no idea how much they help me.
@AngelSix
@AngelSix 6 жыл бұрын
Janakiraman Sattainathan your welcome glad you like it
@diontan7096
@diontan7096 4 жыл бұрын
May god bless you for all your tutorials
@jellehuibregtse9476
@jellehuibregtse9476 4 жыл бұрын
I literally came from your ASP.NET Core tutorial, both are bloody awesome :)
@AngelSix
@AngelSix 4 жыл бұрын
Thanks
@GuildOfCalamity
@GuildOfCalamity 2 жыл бұрын
Great video, as usual.
@copycatzen
@copycatzen 5 жыл бұрын
The world need a c++ tutorial from you
@MultiMinors
@MultiMinors 5 жыл бұрын
the world doesnt need c++ tho
@sutherlandnele
@sutherlandnele 4 жыл бұрын
Thanks Luke. Totally helped.
@loam
@loam 10 ай бұрын
12:42 - nowadays it automatically turns into Func? 30:31 - nowadays also possible) I've had a break in coding for 4 months due to illness (once again), and am rewatching your videos (which I had watched years ago) in order to get back on track, get my brain in the right way of thinking. Your videos always helped me, and I'm very gratefull to you!
@705am
@705am 6 жыл бұрын
Thank you very very much ! I've been following since the beginning , your voice has become music to my ears , no homo lol PS : still waiting for something about databases ,CRUD ...etc
@AngelSix
@AngelSix 6 жыл бұрын
Thanks, yeah the database stuff will come once we make this angelsix site (won't take too long) then with that knowledge behind us we will move onto the ASP.Net server code, and very shortly after that the EF/Database stuff.
@aurimaska6531
@aurimaska6531 6 жыл бұрын
Very good job. Great explanation on the subject. I Would like to see even more advanced videos from you about lambdas in ASP.NET Core 2.
@AngelSix
@AngelSix 6 жыл бұрын
Thanks. I can do a more advanced video on Lambda's in future also
@inambe3987
@inambe3987 5 жыл бұрын
Thank you. It's very helpful.
@megabrogames239
@megabrogames239 6 жыл бұрын
Really useful video thanks
@AngelSix
@AngelSix 6 жыл бұрын
MegaBro Games no problem
@NuKleArNyPL
@NuKleArNyPL 2 жыл бұрын
Nice, thanks!
@Onslaught73
@Onslaught73 6 жыл бұрын
perfectly explained!
@AngelSix
@AngelSix 6 жыл бұрын
Thanks
@umairsaeed5055
@umairsaeed5055 4 жыл бұрын
The best part is that you replay every comment
@bioanu
@bioanu 4 жыл бұрын
Fantastic!!! Could you make a video for using the second part of lambda using for returning an expressions?
@nshirokov
@nshirokov 6 жыл бұрын
I think var “b” was highlighted because you had in search/find bar of the visual studio.
@AngelSix
@AngelSix 6 жыл бұрын
Correct and thanks for the spot
@loam
@loam 5 жыл бұрын
@@AngelSix I had a good laugh from that as well xD Don't get me wrong, I know that you could easilly find that issue, but just because you was not noticing it and your reaction was priceless)
@RioTheHitman
@RioTheHitman 6 жыл бұрын
Nice vid bro
@AngelSix
@AngelSix 6 жыл бұрын
Rio The Hitman thanks
@frankng3111
@frankng3111 6 жыл бұрын
Had a hard time to understand this concept for some time. Your explanation makes it clearer, thanks A6! Can I say the delegates are like a callback method in JS ?
@AngelSix
@AngelSix 6 жыл бұрын
Awesome glad it was useful. Yeah you can form a similarity between a callback in JS and a delegate. MS took their inspiration for delegates from Emac I am sure
@jayjayjaythebrand
@jayjayjaythebrand 6 жыл бұрын
Thanks bro!
@AngelSix
@AngelSix 6 жыл бұрын
Clovy Clov no problem
6 жыл бұрын
Thank you
@AngelSix
@AngelSix 6 жыл бұрын
Ý Nguyễn your welcome
@sokinooo
@sokinooo 4 жыл бұрын
I have a question though, in real world app where should be usually the methods(lambdas) that are passing the delegates in ? For example if there is a code that i know will change with future customer requirements/features. Do you mostly transfer the logic to the UI or prefer to create other classes, libraries for it?
@AngelSix
@AngelSix 4 жыл бұрын
They are normally just other parts of your code. You would want a delegate in part of your code if you know you want to call back up to the caller typically. Such as on reporting success or errors or progress, you can do DownloadFile(string url, Action onProgress) { ... onProgress?.Invoke(50); } to call back and let the caller know its 50% done. The caller would typically just inline this with DownloadFile("...", progress => { Console.WriteLine($"Download progress {progress}% }" );
@sokinooo
@sokinooo 4 жыл бұрын
@@AngelSix Awesome that makes sense. Thank you!
@zbigniewcwiakalski7253
@zbigniewcwiakalski7253 5 жыл бұрын
I really like your explanation. What I would add though are Predicates (you didn't mention about them which are another type of built in delegates) and that the right side of a lambda expression is in fact still an anonimus method (If I'm wrong please correct me). Regards
@AngelSix
@AngelSix 5 жыл бұрын
Yeah I never have needed or used Predicates, in the sense that I just make a Func. I find it more restricting if it was a predicate to change in the future, and see no useful reason to define a predicate. What does it benefit in code anywhere? That's why I've never used them. For the right side of a lambda expression it is called the lambda body. The left side is the input variable, and the => is the lambda token
@AhmedAbdelkaoui
@AhmedAbdelkaoui 6 жыл бұрын
Thank you for the video it was helpful. I have a suggestion if you could make the font size bigger.
@AngelSix
@AngelSix 6 жыл бұрын
Ahmed Abdelkaoui yes sorry I usually do I forgot to turn on present mode this time to make font larger
@MicCheckOneTwo12
@MicCheckOneTwo12 5 жыл бұрын
At 32:22 you assign 'Action actionDelegate' to 'lambdaDelegate(2)'. You can't do this because 'Action' doesn't allow a return type for a delegate definition. It also wouldn't have worked because you have brackets without a 'return" statement. I'm not sure why the intellisense doesn't show the mismatching return output, but if you run the program you get an error trying to print out the invocation of 'actionDelegate()' after doing that. Excellent video though, thanks!
@AngelSix
@AngelSix 5 жыл бұрын
We are assigning the Action as the anonymous lambda () => { } so that's fine. Inside that we call the lambda delegate we don't return or use its return value
@robertozvjerkovic2639
@robertozvjerkovic2639 6 жыл бұрын
33:00 "b" turned brown because you're searching for it (ctrl-f) edit: oh, you got it later on :D Thanks for the vid!
@AngelSix
@AngelSix 6 жыл бұрын
Yeah that one threw me for a while
@DarkVeaerxD
@DarkVeaerxD 5 жыл бұрын
I love you
@AngelSix
@AngelSix 5 жыл бұрын
:)
@adinamarian4581
@adinamarian4581 6 жыл бұрын
Great video again. What is the exactly difference between method and function . Thanks.
@AngelSix
@AngelSix 6 жыл бұрын
A method is the main common name for an actua method (as in something you can call/invoke that has zero or more parameters and an optional return type). A function is another name for it, but is becoming less popular, and also a Function can sometimes refer to the .Net Func type. Typically though method and function are meaning the same thing
@adinamarian4581
@adinamarian4581 6 жыл бұрын
Thanks .
@msc8382
@msc8382 5 жыл бұрын
A method is a specialised usage of a function. A method is a function that is part of an object. A function is a part of a process, usually called a routine. It describes the tiniest possible logic to satisfy an expected output given the input. It is not directly associated with objects. For clarity sake, C is not really object orientated. C therefore only has functions. It does not need to rely on an object definition such as class or struct to operate. C# technically does not have any function support at all. Even the static methods needs to be wrapped in an object definition. For simplicity sake, we speak of a method when a function relies on an underlying instance that the method is directly associated with (e.g. Open for a File class).
@CoderboyPB
@CoderboyPB 4 жыл бұрын
Nice vid, but not the content I expected, I wanted to know about generic Expressions.
@francoislevesque1974
@francoislevesque1974 6 жыл бұрын
Hello, Great Video! Would it be possible to make a video on Generics? Please :D
@francoislevesque1974
@francoislevesque1974 6 жыл бұрын
Ok never mind !! I didn't finish the video and you mention you have one lol!!
@AngelSix
@AngelSix 6 жыл бұрын
Ha yeah
@francoislevesque1974
@francoislevesque1974 6 жыл бұрын
I Started watching you SW API Tut.. I've got a client asking for an app that uses it. They are also great :D
@donnalyons9961
@donnalyons9961 5 жыл бұрын
Helpful! But font very small and hard to read! Maybe zoom it a bit. Most of the screen space is not used.
@AngelSix
@AngelSix 5 жыл бұрын
I zoom in a little more on future videos
@MultiMinors
@MultiMinors 6 жыл бұрын
25:10 so, we can do TSCH TSCH TSCH xdd
@AngelSix
@AngelSix 6 жыл бұрын
Patryk Mikulski I think I should call it the brain train, bringing me information
@brmcc4140
@brmcc4140 3 жыл бұрын
Bro use bigger font. It made me blind to catch the end
@mustafaazyoksul1372
@mustafaazyoksul1372 6 жыл бұрын
When the pace is just right imgur.com/gallery/N2aAd
@AngelSix
@AngelSix 6 жыл бұрын
Thanks :)
@blackclover5561
@blackclover5561 6 жыл бұрын
Fix the name, its called lambda, for the noobs' sake.
@AngelSix
@AngelSix 6 жыл бұрын
Haha yeah its been a typo on the title for a while. Guess I'll edit it now :P
@blackclover5561
@blackclover5561 6 жыл бұрын
AngelSix wow you're fast. Great! I am getting out of the "noob phase" currently, so I'm looking out for the others among me.
@dorcasM30
@dorcasM30 2 жыл бұрын
The sound of your keyboard is so anoying. I can't stand it.
C# Threads, Tasks, Multi-threading & UI Cross-threading
1:07:04
Advanced C#: Lesson 4 - Delegates Events and Lambda expressions
1:09:18
Jesse Dietrichson
Рет қаралды 140 М.
Schoolboy - Часть 2
00:12
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 4,9 МЛН
Delegates in C# - A practical demonstration, including Action and Func
1:09:11
Why Use Dependency Injection?
33:26
AngelSix
Рет қаралды 11 М.
C# Events and Delegates Made Simple | Mosh
32:04
Programming with Mosh
Рет қаралды 938 М.
Writing async/await from scratch in C# with Stephen Toub
1:06:02
C# Events - Creating and Consuming Events in Your Application
1:09:13
iPhone socket cleaning #Fixit
0:30
Tamar DB (mt)
Рет қаралды 18 МЛН
Yanlışlıkla Telefonumu Parçaladım!😱
0:18
Safak Novruz
Рет қаралды 817 М.
#samsung #retrophone #nostalgia #x100
0:14
mobijunk
Рет қаралды 14 МЛН