-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
118 lines (94 loc) · 3.3 KB
/
Copy pathProgram.cs
File metadata and controls
118 lines (94 loc) · 3.3 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.Diagnostics;
using TestDelegate;
class Programm
{
delegate T Operations<T, K1, K2>(K1 val1, K2 val2);
//*
enum OperationType { addition,substraction,multiplation,division};
static int Add(int x, int y) => x + y;
static int Subtract(int x, int y) => x - y;
static int Mult(int x, int y) => x * y;
static float? Division(int x, int y) => y != 0 ? (float)x / (float)y : null;
static int Multiply(int x, int y, out string NameOperation)
{
NameOperation = "*";
return x * y;
}
static int StaticAdd(int x, int y) => x + y;
static void Mess(string s) => Console.WriteLine(s);
static void Ms(string s) => Console.WriteLine("HELLO WORLD!");
delegate int Operation(int x, int y);
delegate int Operationn(int x, int y, out string _NameOperation);
delegate void Message(string x);
delegate void Mes();
static void DoOperation(int x, int y, Operationn op)
{
string typeOperation;
var res = op(x, y, out typeOperation);
Console.WriteLine($"{x} {typeOperation} {y} = {res}");
}
static Operation SelectOperations(OperationType opType)
{
switch (opType)
{
case OperationType.addition:
return Add;
case OperationType.substraction:
return Subtract;
case OperationType.multiplation:
return Mult;
//case OperationType.division:
// return new Operations<float?, int, int> (Division);
default: return null;
}
}
public static void Main()
{
int x, y;
x = 2;y = 3;
Operation oper =StaticAdd;
// var result = oper(x, y);
// Console.WriteLine($" result={ result}");
// foreach (var ls in oper.GetInvocationList())
// Console.WriteLine(ls.Method);
oper += Subtract;
//result = oper(x, y);
// Console.WriteLine($" result={result}");
// foreach (var ls in oper.GetInvocationList())
// Console.WriteLine(ls.Method);
// oper += new Operation(new Programm().Multiply);
// result = oper(x, y);
Console.WriteLine($"{x} {oper.Method.Name} {y} = {oper(x, y)}");
Console.WriteLine("");
foreach (var deleg in oper.GetInvocationList())
{
Operation op = (Operation)deleg;
var s = "";
//if (deleg.Method.Name.Contains(nameof(Subtract)))
// s = "substruct";
Console.WriteLine($"{x} {deleg.Method.Name} {y} = {op(x,y)}");
}
//Message mess = Mess;
//mess += Ms;
//mess("Hi!");
Console.WriteLine("");
Mes ms = Welcome.Print;
ms += new Hello().Display;
ms();
DoOperation(x,y,Multiply);
GenericDelegates.Method();
Console.WriteLine("-------------------");
Operation operation = SelectOperations(opType: OperationType.addition);
Console.WriteLine($"{x} {OperationType.addition.ToString()} {y} = {operation(x, y)}");
Console.ReadKey();
Environment.Exit(0);
}
class Welcome
{
public static void Print() => Console.WriteLine("Welcome");
}
class Hello
{
public void Display() => Console.WriteLine("Привет");
}
}