Objectivde : LINS Funct
  • Func<int, int, int> funcAdd = (x, y) => x + y;
Code :

//File location : C:\BareBone_CSharp\Source_Code\Template
using System;// Namespace Declaration
using System.Collections.Generic;
//csc CsharpLinq1.cs
using System.Linq;
//csc test.cs
// Program start class
namespace testlinq1
{
class CsharpLinq1
{
// Main begins program execution.
static void Main(string[] str1)
{
int n1;int n2;int calc;string a , b;
Console.Write("Enter smaller int to n1':");
a = Console.ReadLine();
Console.Write("Enter larger int to 'n2':");
b = Console.ReadLine();
// with void return will quit command prmpt
if((a =="") & (b==""))
{Console.WriteLine("So Long Command"); return ; }
try
{
// processing as LINQ
n1 =int.Parse(a); n2 =int.Parse(b);
Func<int, int, int> funcAdd = (x, y) => x + y;
calc=funcAdd.Invoke(n1, n2);
Console.Write(" Addtion Operation :");
Console.WriteLine(Convert.ToString(calc));
//
Func<int, int, int> funcDevide = (x, y) => y/x ;
calc=funcDevide.Invoke(n1, n2);
Console.Write(" Divison Operation :");
Console.WriteLine(Convert.ToString(calc));
}
catch (Exception ex)
{
Console.WriteLine("Exit With Grace on Error /n");
Console.WriteLine(ex.ToString());
}
// Console.ReadLine();
}
}
}// end of the name space