Тёмный

C# Advanced Tutorials: The ForEach Method And Functional Programming 

Programming Made EZ
Подписаться 79 тыс.
Просмотров 55 тыс.
50% 1

This "The ForEach Method And Functional Programming" video is part of a series of videos on various Advanced Programming topics in the C# language. In this video you will learn how to convert a foreach loop over a list to a ForEach function that will simplify your code and make it more readable. You will also learn some of the value of functional programming. These C# Advanced Tutorials are designed to help make you a better programmer and learn some of the more advanced topics of the .NET language. These videos stand alone as instructional videos that cover a variety of different advanced topics. You should know at least the basics of the C# language before watching any of them. If you would like to learn the basics of the C# language, you can watch my C# Basics course at • C# Basics
Work Files: github.com/Xip...
C# Advanced Tutorials Playlist: • C# Advanced Tutorials
C# Basics: • C# Basics
Homepage: www.ProgrammingMadeEZ.com
Blog: Techie-tid-bits.blogspot.com
Facebook: Facebook.com/ProgrammingMadeEZ

Опубликовано:

 

6 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 82   
@tinym00n
@tinym00n 7 лет назад
very good video ! you can make it shorter by doing .ForEach(Console.WriteLine);
@ProgrammingMadeEZ
@ProgrammingMadeEZ 6 лет назад
Yes you could because an action is merely a reference to a function that returns void. That function can be either a lambda expression or function like Console.Writeline which returns nothing.
@ProgrammingMadeEZ
@ProgrammingMadeEZ 4 года назад
@Ethan Ansell an action can have multiple parameters. The only difference between an Action and Func is the return type. Action returns void where as Func returns the last type listed in the type parameters.
@shapeshifter8986
@shapeshifter8986 4 года назад
This is a really good way to explain WHY you want to use advanced c# techniques instead of just HOW to do things. This way it makes a lot more sense when you want to step up your coding skills. Very well done!
@akadakad6100
@akadakad6100 4 года назад
Wow I've learnt so much in 30 min than those 2 hrs c# videos by other tutors. Thank you!
@ProgrammingMadeEZ
@ProgrammingMadeEZ 4 года назад
Glad it was helpful!
@EduardoMartinez-dm5pp
@EduardoMartinez-dm5pp 2 года назад
20 minutes to learn something that would be helpfull for life thank you A lot!!!
@4345ghee
@4345ghee 5 лет назад
13:55 I really liked the way you bring in the .ForEach() as a better refactor. This is the most natural way of understanding because otherwise in my head I think, who gives a shit if DisplayName(string name) is there, that's good enough; but the lingering redundancy problem you bring up as "this is an existing feature in the language" is really how that shined out to me if that makes sense so thank you for answering the question of "why care?" so intuitively.
@vitek0585
@vitek0585 6 лет назад
I've not found anything advanced in this video
@JackRus
@JackRus 7 лет назад
The topic is Definitely advanced. Ok, maybe not the topic itself, but the depth of the explanation and the comparison. What is very important (IMO) here, is that Steve explains what is behind lambda expression.
@Layarion
@Layarion 6 лет назад
heh. buddy, you haven't seen "deep" until you watch Jamie Kings videos: ru-vid.complaylists?sort=dd&view=50&shelf_id=5
@acetributon
@acetributon 3 года назад
The " => " syntaxes. In javascript those were called Arrow Functions as it shortens the function call. Seeing this for the first time as a js developer trying to go into C# kinda gave me some hope.
@lionciomorcilla4743
@lionciomorcilla4743 6 лет назад
Sirr!!! thankyou very much... you saved my entire life today
@BrandonChawane
@BrandonChawane 2 года назад
This is very helpful, thank you Steve
@schmidtlach
@schmidtlach 7 лет назад
Great video. Keep up your excellent work! Thanks for your efforts.
@wuzixiao1
@wuzixiao1 2 года назад
For other FP, foreach is named as iter. The inside function signature is a’ -> ()
@ga7853
@ga7853 5 лет назад
Thanks a million, I did not know that you can use ForEach as Method, thanks again.
@Sonny0276
@Sonny0276 7 лет назад
Great Video. Also you could declare " using static System.Console;" and then have ReadLine(), and WriteLine(). No one to write console everytime.
@Amy-ve3ke
@Amy-ve3ke 2 года назад
Loved this video! Thanks 😊
@sushilponnam7433
@sushilponnam7433 7 лет назад
you nailed it man.. really impressed by it thanks a lot.
@KhalidAfridi1
@KhalidAfridi1 3 года назад
Its really *amazing* and made me thinking to use the *single principle* 👍Up
@abhijitv
@abhijitv 5 лет назад
Superb Video ! Steve you are always great
@ernestmedina2448
@ernestmedina2448 6 лет назад
Wow very good video. I found myself doing some of the things talked about. With the list love the foreach. I am thinking you can populate the list with a connection string and a query in SQL as long as its within the {}
@silluarts
@silluarts 6 лет назад
This topic was very Informative and helpful, It would be more better if you would cover more topics same like this one..!!
@abhishekvishnoi2194
@abhishekvishnoi2194 6 лет назад
Beautifully Explained
@warreprovoost4358
@warreprovoost4358 6 лет назад
very well constructed video
@koushikalam8901
@koushikalam8901 7 лет назад
very nice and clear description . Thanks a lot.
@ProgrammingMadeEZ
@ProgrammingMadeEZ 7 лет назад
Thank you!
@michaelshepherdmunemo4414
@michaelshepherdmunemo4414 2 года назад
Thank you it was helpful
@adamnorman85
@adamnorman85 2 года назад
Excellent 👍
@dillonpillay106
@dillonpillay106 4 года назад
wow awesome man . I did not know this.
@BahawalTV
@BahawalTV 5 лет назад
Good video. Thanks.
@tharollomalehase7463
@tharollomalehase7463 4 года назад
ForEach(a => Console.WriteLine(a))
@geoffjames992
@geoffjames992 7 лет назад
Great video, Steve! Nice pace, and some good explanations. I'm a fairly new subscriber to your channel, so I'm looking forward to watching some more of your videos. Just one question regarding the resulting .ForEach(...) near the end of the video: Would one step (even) further into the ForEach(name => Console.WriteLine(name)), just be to use parameter-type inference? Or would this be a better topic to cover in another video?
@ProgrammingMadeEZ
@ProgrammingMadeEZ 7 лет назад
Type inference would probably be left better for another video. This one could be confusing enough already.
@bartjebeltegoed
@bartjebeltegoed 4 года назад
Good video, clear explanation, but I'd say it is intermediate level. Not really beginners, but absolutely not advanced.
@sumitdalal343
@sumitdalal343 4 года назад
awsm content. very well demonstrated. thanks, Steve!!
@ddyakov
@ddyakov 7 лет назад
Hey dude, nice video! Just on a side note, I wanna say that there is another shorter way to do that with: Console.WriteLine(string.Join(" ", new List() {"Name1", "Name2", "Name3"})); Hope this helped. :)
@mkenyahalisi4928
@mkenyahalisi4928 7 лет назад
never thought of joining with newline. Good one!
@ddyakov
@ddyakov 7 лет назад
Thanks :)
@ahmadsaeed7168
@ahmadsaeed7168 7 лет назад
Unfortunately the topic was about ForEach method.
@lot10games
@lot10games 5 лет назад
Thanks
@Coder-zx4nb
@Coder-zx4nb 7 лет назад
6:09 As someone with heavy experience in C# please read: NO NO NO! STOP! You may think that's the slick kool guy way of doing things but there's drawbacks to consider here! 1) This adds two lines of bloat (line for { and } ) for no good reason 2) Say you're using 6 objects to construct the name list. One of the them is null and throws and null ref. You're stack trace will point to the List OtherNames line and not the line of the null object. Great job! You've now obscured the line number in an error in your code. Whereas if you did the other way the line number would be on the Add with the null object and you'd know exactly what went wrong..
@ProgrammingMadeEZ
@ProgrammingMadeEZ 7 лет назад
I get your point, but if you are making an assignment of an object that is the result of a method call, you can watch the method which creates it to see if it is returning null. Also, methods that generate null are a code smell and probably shouldn't be allowed in the first place. Though there are occasions for it, in such cases you should be wrapping them in a null coalescing operator to ensure a value is being placed on your object that is not null.
@choudharyom1
@choudharyom1 4 года назад
awesome... do you have more of these?
@ProgrammingMadeEZ
@ProgrammingMadeEZ 4 года назад
Yup. I cover delegates, events, func, and actions in some other videos of this series.
@alirezanet
@alirezanet 4 года назад
is this "C# Advanced Tutorials" just a click bait ? :/
@sachinkhot5513
@sachinkhot5513 4 года назад
Nice Video
@ProgrammingMadeEZ
@ProgrammingMadeEZ 4 года назад
Thank you!
@mickey8973
@mickey8973 7 лет назад
Surely this isn't "advanced"?
@ProgrammingMadeEZ
@ProgrammingMadeEZ 7 лет назад
Though I understand the concept and explanation may seem simple, designing cleaner, and easier code to read while modifying code to become Functional rather than OOP or Procedural, is not a beginner topic. Perhaps it could be labeled intermediate, but even some of the more advanced and knowledgeable developers do not write code with these things in mind. I should add, this is a bit of an introduction to some videos I plan on writing later on Functional Programming in C#.
@mickey8973
@mickey8973 7 лет назад
+Programming I'm with you there. Writing clean maintainable code isn't maybe something beginners should be focused on. I just was expecting some advanced c# specific topics based on the title. I'm really excited about the functional approach that has been introduced into the c# language. It has made it so much easier to write and maintain in a lot of aspects. I look forward to your videos to come!
@AZ-bu7ss
@AZ-bu7ss 3 года назад
Ok, like. But its simple program. In real world we often hard to use immutable list because at some point we have to add some items to list. Functions is more than for each and one readline function. Well, of course we can use function for one item - and not do foreach inside the function.
@randomactsofgaming845
@randomactsofgaming845 7 лет назад
Great video
@ashokkasar8368
@ashokkasar8368 2 года назад
Not able to watch on mobile as font is very small for moboleb
@bashirabdelwahed
@bashirabdelwahed 7 лет назад
looking forward to master functional programming
@ДаниилСемёнов-п6г
Thank you! I have one question, why didn't you create function like void DisplayName(string name){...} and didn't use it in .ForEach(DisplayName)? It would be better in my opinion.
@ProgrammingMadeEZ
@ProgrammingMadeEZ 7 лет назад
I absolutely could have. You could make a function that does something more complex than just writing to the console window, then call it.
@ДаниилСемёнов-п6г
Thank you for explanation. By the way, it will work with "void DisplayName(string name)" too. Action is the same as void FuncName(string paramName).
@ProgrammingMadeEZ
@ProgrammingMadeEZ 7 лет назад
Yeah I realized after I initially typed up my response that I was being a bit biased towards my own explicitness tendencies.
@Damixx111
@Damixx111 7 лет назад
Даниил Семёнов although a method called "DisplayName(string param)" can be passed as a delegate there, there's no reason to. Making a method that only calls a single other method is weird and not necessary at all. Plus you could technically import the static members of System.Console (using static System.Console;) and even use a method group instead of the lambda. So you can simply write Names.ForEach(WriteLine);
@Layarion
@Layarion 6 лет назад
12:33 i'm gong to say that yes, it is terrible. Right now, that readline is serving a purpose. to create a visual divider, and wait for the user to say they want to see more. thing is, say you come back 10 years from now and look at this code. It'll be faster to figure out why you included ReadLine there if it was put in a method named "VisuallySpaceOutList" than it would be to look at readline and wonder "what purpose is this serving again?"
@kaushikc9803
@kaushikc9803 7 лет назад
Nice video
@alexanderhohle535
@alexanderhohle535 6 лет назад
mega like
@piotrek7628
@piotrek7628 7 лет назад
This is not advanced. This is __beginner__ tutorial.
@felixshfail1
@felixshfail1 6 лет назад
nice man
@unknownalien3837
@unknownalien3837 3 года назад
private static void WriteNames(string[] names){ names.ToList().ForEach(name => Console.WriteLine(name)); } //Provide the list of names as params private static void main(string[] args){ WriteNames(args); } Look at how tiny this has gotten :)
@BeansEnjoyer911
@BeansEnjoyer911 3 года назад
Vs saves on build...
@drxyd
@drxyd Год назад
This isn't advanced... There's some interesting stuff in linq, IEnumerable with yield return, async/await and many other things in c# that can be combined to do higher order programming. There are also lower order things like buffers, unsafe and so on that an advanced programmer would be interested in learning more about; balancing correctness guarantees via the type system, performance and degrees of abstraction etc. Then there's the CLR, reading IL and how to benchmark the dozens of ways that c# lets you implement identical functionality.
@baoshenyi
@baoshenyi 4 года назад
very simple example, no advanced skills, like high order, ValueTuple, Yeild......
@cosmicdarkmatter1128
@cosmicdarkmatter1128 6 лет назад
liked
@vladimirkramar718
@vladimirkramar718 6 лет назад
23 min of talking about of nothing. BTW, All places where I think of the performance I am using "for" instead of "foreach".
@survivalizer
@survivalizer 5 лет назад
It all depends on what the "compiler" does for you and how it interprets it down at the bare wire level. If you want performance you write your own memory manager in C++ or C or even the ASM of your choice for the target platform. Foreach over an IEnumerable (or is it Iterator... I forget the syntax) is faster than for loops because the "compiler" speeds things up on the backend.
@antonsimkin
@antonsimkin 2 года назад
hmm im an amateur but didnt find anything advanced here
@s1pl
@s1pl 4 года назад
If this is advanced then I'm worried for the industry XD
@icsharpernow2938
@icsharpernow2938 7 лет назад
Advice from one programmer to another: Keep your variable declarations at the top of your code and define it's value in the body. It makes it clean and easily readable. Also don't forget to comment. Keep up the good work!
@ProgrammingMadeEZ
@ProgrammingMadeEZ 7 лет назад
Thank you for the advice, but I actually disagree with it. LOL First, declarations should be made within the scope of where you are going to use it to avoid invalid state changes.  Second, comments are an indication that either A) you aren't following the SRP, or B) you need to name things better. Comments are often misleading and outdated which typically causes more problems than it solves.  If you are coding all by yourself, then it's not so bad.  But when others are reading your code, if the methods are big or the names are poorly named, no amount of comments will make them like you.
@unknownalien3837
@unknownalien3837 3 года назад
@@ProgrammingMadeEZ I disagree. Comments are important to understanding the mindset and the intentions of the original programmer. Comments are to be used sparsely, sure, but they're crucial to maintainable code. As I'm sure you're aware, in real professional life you're (most likely) not writing code about displaying names in a loop or assigning names to variables.
@SashoApostolovski
@SashoApostolovski 7 лет назад
HYPE
@ProgrammingMadeEZ
@ProgrammingMadeEZ 7 лет назад
?
@sexyeyes6203
@sexyeyes6203 4 года назад
This are very basic ... in real world ... you use database ...
Далее
Master the Design of Functional Types in C#
17:53
Просмотров 16 тыс.
Epic Reflex Game vs MrBeast Crew 🙈😱
00:32
Просмотров 2,9 млн
Dear Functional Bros
16:50
Просмотров 517 тыс.
Functional Programming in C#
47:26
Просмотров 20 тыс.
Dependency Injection, The Best Pattern
13:16
Просмотров 836 тыс.
Every single feature of C# in 10 minutes
9:50
Просмотров 134 тыс.
Object-Oriented Programming is Bad
44:35
Просмотров 2,3 млн
Top 10 C# Best Practices (plus bonuses)
57:28
Просмотров 511 тыс.
Epic Reflex Game vs MrBeast Crew 🙈😱
00:32
Просмотров 2,9 млн