User can also create the asynchronous processing by using the async key word which is known as async lambdas the snippet below demonstrates the async lambda.
[csharp]
Func<Task<string>> getWordAsync = async() => “splessons”;
[/csharp]
Lambda Standard Query Operators
Lambda Expression in a query operator is demonstrated by the requirements and which works on the each element in the sequence but not on whole sequence. user can give the own logic's by the lambda expression into the standard query operator. The code below demonstrates the using of Lambda expression by using "Where" operator in c#.
[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lambdaexample
{
class Program
{
static void Main(string[] args)
{
int[] fibNum = { 1, 2, 3, 5, 8, 13, 21, 34, 50 };
double averageValue = fibNum.Where(num => num % 2 == 1).Average();
Console.WriteLine(averageValue);
Console.ReadLine();
}
}
}
[/csharp]
Result
Compiling and execute the above code in a Visual Studio then user can get the output is a shown below.
The code below demonstrates the using of Lambda expression by using "Where" operator in VB.
[csharp]
Module Module1
Sub Main()
Dim fibNum As Integer() = {1, 2, 3, 5, 8, 13, 21, 34, 50}
Dim averageValue As Double = fibNum.Where(Function(num) num Mod 2 = 1).Average()
Console.WriteLine(averageValue)
Console.ReadLine()
End Sub
End Module
[/csharp]
Result
Compiling and execute the above code in a Visual Studio then user can get the output is a shown below.