C Sharp/Lambda
< C SharpIntroduction
Lambda expressions are one of the forms of anonymous methods in .Net, which can be used for passing as inputs for local functions or as an expression to execute inline. Lambda expressions are particularly helpful for writing LINQ query expressions.
Lambda expressions helps in simplifying the logical statements and looping statements. This is possible for enumerable types where we can use Lambda expressions instead of writing looping statements or logical statements in multiple execution lines making code look cleaner and simple.
Example
using System;
using System.Linq;
namespace Program
{
class Program
{
public static void Main(string [] args)
{
int[] myInteger = new int[] {1,2,3,4,5};
var getNumbers = from num in myInteger where num > 1 select num;
foreach(var i in getNumbers)
{
Console.WriteLine(i);
}
Console.ReadKey();
}
}
}
This article is issued from Wikiversity - version of the Thursday, July 16, 2015. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.