/
Nov16AnonymusFunctions.cs
62 lines (61 loc) · 1.6 KB
/
Nov16AnonymusFunctions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AnonymusFunctions
{
public delegate void D1();
public delegate void D2(int a);
public delegate int D3(int a, int b);
class Program
{
static D1 d1; static D2 d2; static D3 d3;
static void Main(string[] args)
{
int a = 200;
CreateUnnamed(ref a, 500);
d1();
CreateUnnamed(ref a, 1000);
Test();
WriteLine("\n");
CreateLyambda();
Test();
}
public static void Test()
{
d1();
d2(175);
WriteLine(d3(17, 13));
}
public static void CreateUnnamed(ref int x, int y)
{
int c = 150;
d1 = delegate
{
WriteLine("Calling Annonymus Without Param");
//int x = 10;
//int y = 20;
//int c = 30;
//Console.WriteLine("Ref Param = " + x);
WriteLine("Param = " + y);
WriteLine("Local Var = " + c);
};
d2 = delegate
{
WriteLine("Calling Annonymus By Param ");
};
d3 = delegate
{
return 10;
};
}
public static void CreateLyambda()
{
d1 = () => WriteLine("Calling Lyambda");
d2 = a => WriteLine("Param = " + a);
d3 = (a, b) => a > b ? a * b : b - a;
}
}
}