Understand C# LAMBDA Expressions in only 2 minutes!

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ต.ค. 2024
  • 🔥 Wanna KNOW how to use LAMBDA in C#? THIS is the video you have been looking for!
    🚀 C# Progress Academy - Become a senior C# developer: academy.tutori...
    Here is the article: tutorials.eu/w...
    We'll make sure to turn you into a true developer in no time!
    So, what is C#?
    C# (pronounced "See Sharp") is a modern, object-oriented, and type-safe programming language. C# enables developers to build many types of secure and robust applications that run in .NET. C# has its roots in the C family of languages and will be immediately familiar to C, C++, Java, and JavaScript programmers. This tour provides an overview of the major components of the language in C# 8 and earlier. If you want to explore the language through interactive examples, try the introduction to C# tutorials.
    And what is LAMBDA, then?
    You use a lambda expression to create an anonymous function. Use the lambda declaration operator to separate the lambda's parameter list from its body.
    Any lambda expression can be converted to a delegate type. The delegate type to which a lambda expression can be converted is defined by the types of its parameters and return value. If a lambda expression doesn't return a value, it can be converted to one of the Action delegate types; otherwise, it can be converted to one of the Func delegate types. For example, a lambda expression that has two parameters and returns no value can be converted to an Action delegate. A lambda expression with one parameter that returns a value can be converted to a Func delegate.
    To learn more, make sure to watch the video, and we promise you that you'll become a C# developer by the end of the course! Have fun!
    #csharp #coding #tutorial #learn #microsoft #net #lambdaexpression #dotnet
    TAGS
    Tutorials,Tutorial,Programming,Course,Learn,Step by step,guide,development,programmer,video course,video tutorial,learn how to,how to,visual studio,c#,.net,.net core,dotnet,visual studio 2019,core,code,asp,asp net,c sharp,coding,csharp,programming,api,rest api,rest,json,http,api testing,software development,c# tutorial for beginners,c# tutorial,c# restsharp tutorial,how to call post api in c#,csharp api,step by step,mvc,web api,rest api tutorial
    tutorialsEU offers you free video tutorials about programming and development for complete beginners up to experienced programmers.
    This includes C#, Unity, Python, Android, Kotlin, Machine Learning, etc.
    Stay tuned and subscribe to tutorialsEU: goo.gl/rBFh3x
    C#: / @tutorialseuc
    Facebook: / tutorialseu-1093802040...
    LinkedIn: / tutorialseu
    Discord: / discord

ความคิดเห็น • 48

  • @tutorialsEUC
    @tutorialsEUC  ปีที่แล้ว +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 ปีที่แล้ว +43

    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 ปีที่แล้ว +2

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

    • @ErfanDjojan
      @ErfanDjojan 5 หลายเดือนก่อน +1

      @@DannysGalaxyTab Yes and unnecessarily so.

  • @MajorSquiggles
    @MajorSquiggles ปีที่แล้ว +43

    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 ปีที่แล้ว +6

      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 ปีที่แล้ว +7

      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 10 หลายเดือนก่อน

      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 10 หลายเดือนก่อน

      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 10 หลายเดือนก่อน +4

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

  • @RickSteadX
    @RickSteadX ปีที่แล้ว +25

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

    • @Doks_Coders
      @Doks_Coders 8 หลายเดือนก่อน +1

      Exactly

  • @racmanov
    @racmanov 11 หลายเดือนก่อน +9

    That is not lambda tutorial that is Linq tutorial

  • @BerkBayar
    @BerkBayar 22 วันที่ผ่านมา +1

    Thank you for clear definition

  • @slowfuse
    @slowfuse 6 หลายเดือนก่อน +1

    video is 4 minutes long.
    i'm out

  • @MidnightTsuki
    @MidnightTsuki ปีที่แล้ว +6

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

  • @whitetiana3022
    @whitetiana3022 ปีที่แล้ว +2

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

  • @KillAllCommies2
    @KillAllCommies2 หลายเดือนก่อน

    I now understand lambda operations even less, thanks!

  • @სერგიორმოცაძე
    @სერგიორმოცაძე 3 หลายเดือนก่อน

    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

  • @AndreasToth
    @AndreasToth 8 หลายเดือนก่อน +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.

  • @kitsurubami
    @kitsurubami ปีที่แล้ว +4

    What about using a Lambda expression without Linq

    • @tutorialsEUC
      @tutorialsEUC  ปีที่แล้ว

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

  • @_keja_
    @_keja_ ปีที่แล้ว +4

    very well said. thank you

  • @thatguyty96
    @thatguyty96 ปีที่แล้ว +1

    Thankyou sir. Also, youre accent is awesome.

  • @LionKing_Mufasa
    @LionKing_Mufasa 11 หลายเดือนก่อน +1

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

  • @cheeseyf1ghter
    @cheeseyf1ghter ปีที่แล้ว +1

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

  • @risingforce9648
    @risingforce9648 ปีที่แล้ว

    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.

  • @barenyabinayak3255
    @barenyabinayak3255 10 หลายเดือนก่อน

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

  • @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

  • @JonWoo
    @JonWoo 10 หลายเดือนก่อน

    How does this speed up your code?

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

    Simple, fast, clear.

  • @kimutaifelix9092
    @kimutaifelix9092 ปีที่แล้ว

    You are a good teacher

  • @caseyspaulding
    @caseyspaulding ปีที่แล้ว

    Thank you

  • @zazakage62
    @zazakage62 ปีที่แล้ว

    thanks

  • @Vykhari1
    @Vykhari1 ปีที่แล้ว

    Thank you!!

  • @TheHabibpk
    @TheHabibpk ปีที่แล้ว

    I really appreciate for very simple explaination

  • @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

  • @simonroyjonesuk
    @simonroyjonesuk ปีที่แล้ว +1

    Really helpful. Thanks

  • @illumi98
    @illumi98 ปีที่แล้ว +2

    Simple and clear. Thank you.