Finished Using Func and Action Types
parent
e0d20ef793
commit
066f46a48c
|
@ -10,6 +10,19 @@ namespace Features
|
||||||
// Modelling a company in this project
|
// Modelling a company in this project
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
/* Generic Delegate & Lambda Expression */
|
||||||
|
Func<int, int> square = x => x*x;// Define a generic delegate functions named square for square operation
|
||||||
|
Func<int, int, int> add = (x, y) =>
|
||||||
|
{
|
||||||
|
int temp = x + y;
|
||||||
|
return temp;
|
||||||
|
};
|
||||||
|
|
||||||
|
Action<int> write = x => Console.WriteLine(x);
|
||||||
|
write(square(add(3, 5)));
|
||||||
|
|
||||||
|
/* LINQ & C# */
|
||||||
|
|
||||||
IEnumerable<Employee> developers = new Employee[]
|
IEnumerable<Employee> developers = new Employee[]
|
||||||
{
|
{
|
||||||
new Employee {Id = 1, Name = "Scott"},
|
new Employee {Id = 1, Name = "Scott"},
|
||||||
|
@ -35,7 +48,9 @@ namespace Features
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var employee in developers.Where(x => x.Name.StartsWith("S")))
|
foreach (var employee in developers
|
||||||
|
.Where(e => e.Name.Length == 5)
|
||||||
|
.OrderBy(e => e.Name))
|
||||||
{
|
{
|
||||||
Console.WriteLine(employee.Name);
|
Console.WriteLine(employee.Name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue