Understand C# LAMBDA Expressions in only 2 minutes!

Поділитися
Вставка
  • Опубліковано 2 лют 2025

КОМЕНТАРІ • 52

  • @tutorialsEUC
    @tutorialsEUC  2 роки тому +3

    🚀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!

  • @brrrrr256
    @brrrrr256 Рік тому +51

    This does not go anywhere into a discussion of Delegates or Anonymous Methods - which is what Lambda Expressions are built on top of.

    • @DannysGalaxyTab
      @DannysGalaxyTab Рік тому +4

      Well yeah but that would complicate the entire video wouldn't it.

    • @ErfanDjojan
      @ErfanDjojan 9 місяців тому +1

      @@DannysGalaxyTab Yes and unnecessarily so.

  • @racmanov
    @racmanov Рік тому +17

    That is not lambda tutorial that is Linq tutorial

  • @MajorSquiggles
    @MajorSquiggles Рік тому +60

    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.

    • @DiegoSynth
      @DiegoSynth Рік тому +9

      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.

    • @wiljagerhardt1219
      @wiljagerhardt1219 Рік тому +14

      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.

    • @Banalny_Banan
      @Banalny_Banan Рік тому +1

      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

    • @danielbrenjuk7291
      @danielbrenjuk7291 Рік тому

      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

    • @JonWoo
      @JonWoo Рік тому +5

      This is just a click bait marketing video for their business. It doesn't teach you anything of value.

  • @RickSteadX
    @RickSteadX Рік тому +31

    It's more of LINQ lesson than lambda expressions..

  • @BerkBayar
    @BerkBayar 4 місяці тому +1

    Thank you for clear definition

  • @LionKing_Mufasa
    @LionKing_Mufasa Рік тому +1

    Thank you very much, you saved me at the last time of my assignment.

  • @thatguyty96
    @thatguyty96 Рік тому +1

    Thankyou sir. Also, youre accent is awesome.

  • @kj.xx23
    @kj.xx23 Рік тому +4

    very well said. thank you

  • @MidnightTsuki
    @MidnightTsuki Рік тому +7

    ... I feel like I was lied to in my life.

  • @cheeseyf1ghter
    @cheeseyf1ghter Рік тому +1

    Great Video, thank you so much!!
    (What font is that?)

  • @barenyabinayak3255
    @barenyabinayak3255 Рік тому

    Thank you Very much for this explanation within sort time.👍

  • @kimutaifelix9092
    @kimutaifelix9092 Рік тому

    You are a good teacher

  • @KillAllCommies2
    @KillAllCommies2 5 місяців тому +1

    I now understand lambda operations even less, thanks!

  • @whitetiana3022
    @whitetiana3022 Рік тому +2

    i absolutely despise the lambda operator because it does about 10 different things depending on how you use it.

  • @kitsurubami
    @kitsurubami 2 роки тому +4

    What about using a Lambda expression without Linq

    • @tutorialsEUC
      @tutorialsEUC  2 роки тому

      Yes, you for sure do that: stackoverflow.com/questions/1791510/can-lambdas-be-used-without-linq
      We can also create a video on that :)

  • @AndreasToth
    @AndreasToth Рік тому +1

    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.

  • @ВолодимирДрогомирецький-ж1и

    Simple, fast, clear.

  • @zazakage62
    @zazakage62 Рік тому

    thanks

  • @Vykhari1
    @Vykhari1 Рік тому

    Thank you!!

  • @caseyspaulding
    @caseyspaulding Рік тому

    Thank you

  • @AstralNostalgia
    @AstralNostalgia Рік тому

    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.

  • @JonWoo
    @JonWoo Рік тому

    How does this speed up your code?

  • @isuckatthisgame
    @isuckatthisgame 2 місяці тому

    3:07 Lambda expression has nothing to do with iteration.

  • @TheHabibpk
    @TheHabibpk Рік тому

    I really appreciate for very simple explaination

  • @awdsgrgde6979
    @awdsgrgde6979 Рік тому

    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.

    • @programmingpersistence5716
      @programmingpersistence5716 Рік тому

      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

  • @burakdemirh
    @burakdemirh Рік тому

    so is sortedByAge an array?

    • @charichard09
      @charichard09 Рік тому +3

      Late but for future readers, sortedByAge is not an array but a List, created from sorting List people. Hope that helps!

    • @burakdemirh
      @burakdemirh Рік тому

      @@charichard09 thanks man

  • @illumi98
    @illumi98 Рік тому +2

    Simple and clear. Thank you.

  • @slowfuse
    @slowfuse 10 місяців тому +1

    video is 4 minutes long.
    i'm out

  • @სერგიორმოცაძე
    @სერგიორმოცაძე 7 місяців тому

    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

  • @simonroyjonesuk
    @simonroyjonesuk Рік тому +1

    Really helpful. Thanks