🚀C# Progress Academy - Become a senior C# developer: academy.tutorials.eu/p/csharp-progress-academy Here is the article: tutorials.eu/what-are-lambda-expressions-in-c-sharp/ We'll make sure to turn you into a true developer in no time!
This is the worst explanation. It doesn't clarify anything and only leaves more questions. How does it know that p is a person? What is the point of typing out p => p.Age instead of just typing OrderBy(Age)? What do all the other parts of the expression do? They aren't just there for no reason. How does it know which way to sort? Maybe instead of sorting by oldest to youngest I want youngest to oldest. You mostly explained what the end result was but not how it works. I can't use something if I don't know how it works.
Yes, yes, yes. Exactly all of this. And when you are NOT a beginner, you write "those crazy for loops" very quickly, because you are doing the reasoning, and you know what you do. I really don't like when programming languages magically do things with no cohesion. And there's obviously explanation to how things happen, but going down into the rabbit hole ends up being much more of a pain than writing the for loop. Microsoft is an expert on magically doing things, hiding the backstage, and clogging the pipeline: You need an html page > you end up with a full environment, with automated authentication, DB bindings, razor pages, MVC models, middleware, etc., etc., etc. Horrible, unscalable, unportable, slow, shit.
p: This is a lambda parameter. It represents an individual element of the people collection during the sorting process. You can think of it as a temporary variable that holds each element of the collection one by one while sorting. =>: This is the lambda operator, which separates the lambda parameter (p) from the lambda body (p.Age). It indicates that the lambda parameter is used to produce the value on the right side of the operator. p.Age: This is the lambda body. It specifies the property Age of the p parameter. In this context, p represents each Person object in the people collection, and p.Age represents the age of each person. When the OrderBy method is executed with the (p => p.Age) lambda expression, it compares the Age property of each Person object and sorts the collection in ascending order based on these ages. In summary, (p => p.Age) is a concise way to provide a sorting key for the OrderBy method. It instructs the method to sort the elements based on the Age property of each Person object in the people collection. In Simple Terms (p => ... ): This is like a short formula that says "for each person in the list, do something." p: It represents one person in the list at a time. It's like a placeholder for each person while the computer is sorting them. p.Age: This says "look at the Age property of the person." Putting it all together, (p => p.Age) means "for each person in the list, look at their Age, and use that value to sort them from youngest to oldest." So, people.OrderBy(p => p.Age) takes the list of people and returns a new sorted list of people, with the youngest person first and the oldest person last, based on their ages. The original list remains unchanged.
OrderBy can sort something by int. So for it to work, and sort a list of Person objects you need to somehow help it to get those integers from Person objects. It gives you a Person (p is a variable name), then you return p.Age. lambda is a way to define a method with left hand side being input params and right hand side - what you return
P is just a variable name, the name person is the name of the list, and the p => p.Age just tells c# to sort through every element in the list by the value that is contained in the part of the list called Age. OrderBy tells the lambda to sort the list based on provided conditions
You really shouldn't say that p is a Person but that it is a parameter which you have chosen to call p and which is of the list item type, i.e., Person.
the "input" is "people" and the "expression" is "p"? that is the key for lamda? . I like your video but I am wondering the background behind lamda, cause I am reading the documetnation as well.
One thing I don't get: how does the program know that person is an element in this list? I may be overcomplicating, but I am horribly stuck on this lambda expression syntax for some reason.
Basically if someone wants to understand and had to watch this bullshit The left side of the lambda expression is just parameter keep in mind that lambda is basically function but pretty small one so left side of the lambda is parameter and then comes the code what you want to do with that prameter
🚀C# Progress Academy - Become a senior C# developer: academy.tutorials.eu/p/csharp-progress-academy
Here is the article: tutorials.eu/what-are-lambda-expressions-in-c-sharp/
We'll make sure to turn you into a true developer in no time!
This does not go anywhere into a discussion of Delegates or Anonymous Methods - which is what Lambda Expressions are built on top of.
Well yeah but that would complicate the entire video wouldn't it.
@@DannysGalaxyTab Yes and unnecessarily so.
That is not lambda tutorial that is Linq tutorial
It's more of LINQ lesson than lambda expressions..
Exactly
This is the worst explanation. It doesn't clarify anything and only leaves more questions. How does it know that p is a person? What is the point of typing out p => p.Age instead of just typing OrderBy(Age)? What do all the other parts of the expression do? They aren't just there for no reason. How does it know which way to sort? Maybe instead of sorting by oldest to youngest I want youngest to oldest. You mostly explained what the end result was but not how it works. I can't use something if I don't know how it works.
Yes, yes, yes. Exactly all of this.
And when you are NOT a beginner, you write "those crazy for loops" very quickly, because you are doing the reasoning, and you know what you do.
I really don't like when programming languages magically do things with no cohesion. And there's obviously explanation to how things happen, but going down into the rabbit hole ends up being much more of a pain than writing the for loop.
Microsoft is an expert on magically doing things, hiding the backstage, and clogging the pipeline:
You need an html page > you end up with a full environment, with automated authentication, DB bindings, razor pages, MVC models, middleware, etc., etc., etc. Horrible, unscalable, unportable, slow, shit.
p: This is a lambda parameter. It represents an individual element of the people collection during the sorting process. You can think of it as a temporary variable that holds each element of the collection one by one while sorting.
=>: This is the lambda operator, which separates the lambda parameter (p) from the lambda body (p.Age). It indicates that the lambda parameter is used to produce the value on the right side of the operator.
p.Age: This is the lambda body. It specifies the property Age of the p parameter. In this context, p represents each Person object in the people collection, and p.Age represents the age of each person.
When the OrderBy method is executed with the (p => p.Age) lambda expression, it compares the Age property of each Person object and sorts the collection in ascending order based on these ages.
In summary, (p => p.Age) is a concise way to provide a sorting key for the OrderBy method. It instructs the method to sort the elements based on the Age property of each Person object in the people collection.
In Simple Terms
(p => ... ): This is like a short formula that says "for each person in the list, do something."
p: It represents one person in the list at a time. It's like a placeholder for each person while the computer is sorting them.
p.Age: This says "look at the Age property of the person."
Putting it all together, (p => p.Age) means "for each person in the list, look at their Age, and use that value to sort them from youngest to oldest."
So, people.OrderBy(p => p.Age) takes the list of people and returns a new sorted list of people, with the youngest person first and the oldest person last, based on their ages. The original list remains unchanged.
OrderBy can sort something by int. So for it to work, and sort a list of Person objects you need to somehow help it to get those integers from Person objects. It gives you a Person (p is a variable name), then you return p.Age. lambda is a way to define a method with left hand side being input params and right hand side - what you return
P is just a variable name, the name person is the name of the list, and the p => p.Age just tells c# to sort through every element in the list by the value that is contained in the part of the list called Age. OrderBy tells the lambda to sort the list based on provided conditions
This is just a click bait marketing video for their business. It doesn't teach you anything of value.
Thank you very much, you saved me at the last time of my assignment.
Thankyou sir. Also, youre accent is awesome.
Thank you for clear definition
... I feel like I was lied to in my life.
very well said. thank you
What about using a Lambda expression without Linq
Yes, you for sure do that: stackoverflow.com/questions/1791510/can-lambdas-be-used-without-linq
We can also create a video on that :)
I now understand lambda operations even less, thanks!
i absolutely despise the lambda operator because it does about 10 different things depending on how you use it.
You are a good teacher
Thank you Very much for this explanation within sort time.👍
You really shouldn't say that p is a Person but that it is a parameter which you have chosen to call p and which is of the list item type, i.e., Person.
Great Video, thank you so much!!
(What font is that?)
How does this speed up your code?
3:07 Lambda expression has nothing to do with iteration.
the "input" is "people" and the "expression" is "p"? that is the key for lamda? . I like your video but I am wondering the background behind lamda, cause I am reading the documetnation as well.
One thing I don't get: how does the program know that person is an element in this list? I may be overcomplicating, but I am horribly stuck on this lambda expression syntax for some reason.
the OrderBy already knows its expecting a value to be there, give the value any name and it will represent each element in the array or List
Simple, fast, clear.
I really appreciate for very simple explaination
Glad you like it!
Thank you!!
so is sortedByAge an array?
Late but for future readers, sortedByAge is not an array but a List, created from sorting List people. Hope that helps!
@@charichard09 thanks man
Thank you
thanks
Really helpful. Thanks
Simple and clear. Thank you.
Basically if someone wants to understand and had to watch this bullshit
The left side of the lambda expression is just parameter keep in mind that lambda is basically function but pretty small one so left side of the lambda is parameter and then comes the code what you want to do with that prameter
video is 4 minutes long.
i'm out