C# LAMBDA Expressions and ANONYMOUS Functions Tutorial | 2021

Поделиться
HTML-код
  • Опубликовано: 6 июн 2024
  • In this video, you will learn about Lambda Expressions as well as Anonymous Function in C#
    🚀 Master C# and .NET programming EASILY with our best-selling C# Masterclass: bit.ly/47Hk3u7
    An anonymous method is a method without a name. Anonymous methods in C# can be defined using the delegate keyword and can be assigned to a variable of the delegate type.
    This means we don't have to define a method of our own each time we want to call a method that needs a delegate, since maybe we want to call it once, so defining a dedicated delegate every time we need one can ruin the code structure very fast.
    We will also learn about Lambda expression, which will simplify the creation of anonymous methods even more!.
    The difference between an expression lambda and a statement lambda is on the left side of the goes to operator an expression lambda will have an expression (one line of code) where a statement lambda will have a code block { some lines of code }.
    Anonymous methods can help us to write the code blocks in-line, where delegates are required.
    In C#3.0 Lambda expressions were introduced. It provides a simple, more compact, functional syntax to write anonymous methods.
    “Click”
    The word lambda is taken from the lambda calculus, where everything is expressed in terms of functions.
    We will be using lambda expressions to create anonymous functions/methods.
    To create a lambda expression,
    We need to use the lambda declaration operator (also read as “goes into or goes to”) to separate the lambda's parameter list from its body.
    A lambda expression can have one of the following two forms:
    -Expression lambda that has an expression (one line of code) as its body.
    -Statement lambda that has a statement block (executing more than one line of code) as its body:
    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

Комментарии • 16

  • @tutorialsEU
    @tutorialsEU  2 года назад +1

    🚀Master C# and .NET programming EASILY with our best-selling C# Masterclass: bit.ly/47Hk3u7

  • @colins2
    @colins2 2 года назад +7

    Probably the clearest explanation of Lamdas that I have seen.

  • @justynak.6686
    @justynak.6686 2 года назад +5

    I don't know if it's because it's directed for beginners, you're probably already aware that
    at 12:07 you don't need to write the if else statement at all, just put return keyword before the condition written in the if. Less typing :)

  • @psychoclips6817
    @psychoclips6817 Год назад

    This was an awesome explanation. You kept it clear and simple. Plus you showed exactly how the functions were being used so nothing was left to be guessed.

  • @Syed.KhubaibAli
    @Syed.KhubaibAli 2 месяца назад

    Thankyou for such a nice explanation

  • @leluconygmemuakan1437
    @leluconygmemuakan1437 Год назад

    Thank very much buddy

  • @TheManChise
    @TheManChise Год назад

    Very nice explanation of lambdas..

  • @shaurya007
    @shaurya007 2 года назад +2

    Could you please do some more tutorials on basics of Kotlin in Android Studio

    • @tutorialsEU
      @tutorialsEU  2 года назад +1

      I will update the android 10 course to android 12 and there will be a bunch of kotlin basics coming

    • @shaurya007
      @shaurya007 2 года назад

      @@tutorialsEU Thank You very much 🥰🥰

  • @ghosthunter9897
    @ghosthunter9897 Год назад

    Hey man how can I call function inside lamda expression?

  • @ronen124
    @ronen124 2 года назад +1

    good
    (anonymous)

  • @Jel.Awesh.M
    @Jel.Awesh.M 2 года назад

    In other words, a delegate is contract for methods as an interface is a classes, isn't it?

    • @user-pf9jv1fl2n
      @user-pf9jv1fl2n 2 года назад +2

      A delegate points to a particular method signatures. And can point to multiple method signatures. A interface is a essentially like a contract that you are essentially agreeing to. For example. A classic example would be Innumerable it's a interface and anything that inherits from it will be forced to also include whatever properties the interface has. Since when you inherit from a interface you are agreeing that you will provide every property method etc from the interface. That being said. You're probably wondering why is this even useful. Imagine you want to loop through a bunch of different objects that are somewhat similar. How can you gurantee to the that function that these similar classes will even have the same property. You would do that with a interface because any class thay inherits from a interface will by contract be forced to implement everything that the interface has or more. And since you know now all the inherited objects that inherit from the particular interface have implemented the fields. You can do something like this void loop(Innumerable en)
      And anything that inherits Innumerable you can access similar information since they would have implemented similar data. This is the case for collections so lists arrays etc. This is why we are able to use foreach loop on collections because all the collections inherit the interface Innumerable which one of its properties is the getenumberator method. Hope this helped.

    • @ArnasBies
      @ArnasBies Год назад

      @@user-pf9jv1fl2n Thanks it helped a lot
      (btw your probably meant IEnumerable not Innumerable)