This C# program demonstrates how the lambda operator is used. A lambda expression is a method with a slightly simpler syntax.
using System;
using System.Collections.Generic;
namespace XoaX {
class Program {
public class CEvangelist {
public string msName;
public string msSymbol;
}
static void Main(string[] args) {
List<CEvangelist> qaEvangelists = new List<CEvangelist>() {
new CEvangelist() { msName = "Matthew", msSymbol = "Man" },
new CEvangelist() { msName = "Mark", msSymbol = "Lion" },
new CEvangelist() { msName = "Luke", msSymbol = "Ox" },
new CEvangelist() { msName = "John", msSymbol = "Eagle" }
};
Console.WriteLine("Use a lambda expression:");
// Find all evangelists with a symbol name of length greater than 3
List<CEvangelist> qaFound = qaEvangelists.FindAll(e => (e.msSymbol.Length > 3));
Console.WriteLine("Evangelists with symbol names longer than 3 characters.");
foreach (CEvangelist qCurr in qaFound) {
Console.WriteLine("Name = {0}, Symbol = {1}", qCurr.msName, qCurr.msSymbol);
}
}
}
}
Use a lambda expression: Evangelists with symbol names longer than 3 characters. Name = Mark, Symbol = Lion Name = John, Symbol = Eagle Press any key to continue . . .
© 20072024 XoaX.net LLC. All rights reserved.