Monday, June 23, 2025 14:29

Posts Tagged ‘lambda expression’

LINQ

Monday, May 24th, 2021

Finally, we now know enough to start talking about LINQ, which is an acronym for Language Integrated Query which is basically just a fancy way of doing queries and SQL-like things in C#. If you don’t know what SQL is, you should probably research about it a bit first, but, at a macro level, SQL (Structured Query Language) is just a language for interacting with databases.… Read more

Closures

Sunday, February 2nd, 2020

Let’s consider the following Action:

using System;

namespace HelloWorld
{

    public class Program
    {
        public static void Main()
        {
            int i = 0;

            Action a = () => i++;

            a();
            a();
            a();

            Console.WriteLine(i);

            Console.Read();
        }
    }
}

From the lesson Func and Action, you remember that an Action is just a delegate that returns void and takes between 0 and 16 parameters of any type.… Read more

Anonymous methods

Saturday, February 1st, 2020

Remember from the lesson lambda expressions that we can declare a method locally, without a name, and use it only in one place, where we declare it. This is an example of a lambda expression:

using System;

namespace HelloWorld
{

    public class Program
    {
        delegate bool SomeDelegate(int _param);

        public static void Main()
        {
            SomeDelegate _delegate = i => i > 5;

            Console.Read();
Read more

Lambda expressions

Sunday, January 12th, 2020

In the previous lesson I was writing that we can further improve our code by using lambda expressions. A lambda expression is a convenient way of defining an anonymous (unnamed) function that can be passed around as a variable or as a parameter to a method call.… Read more