Code :
using System;
using System.Linq;
using System.Linq.Expressions;
// Simple_lamba_object2.cs
namespace ExpressionTreeThingy
{
class Program
{
// declaring a delegate
delegate void Delg1(string str1);
//Declare a method
static void Display(string str2)
{
Console.WriteLine("display delegated for: {0}", str2);
}
static void Main(string[] args)
{
//this is an object. extended with LINQ
Expression<Func<int, int>> expr = (x) => x * 5;
//compiles the object to a CLR delegate, at runtime
var var1 = expr.Compile();
//invoking a delegate at this point
Console.WriteLine(var1(5));
//creating instance of delegate
Delg1 delg1 = new Delg1(Display);
string str3 = "Hi there";
delg1(str3);
//
Console.ReadKey();
}
}
}
|