-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmulti_cast_delegate.cs
53 lines (38 loc) · 1014 Bytes
/
multi_cast_delegate.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
using System;
delegate void strMode(ref string str);
class Program
{
static void Main(string[] args)
{
string s = "Adil Aslam";
strMode strOp;
strMode replace = replaceSpaces;
strMode remove = removeSpaces;
strMode reverse = reverseString;
strOp = replaceSpaces;
strOp += removeSpaces;
strOp += reverseString;
strOp(ref s);
Console.WriteLine(s);
strOp -= replaceSpaces;
strOp(ref s);
Console.WriteLine(s);
Console.ReadLine();
}
static void replaceSpaces(ref string s){
s.Replace(' ', '-');
}
static void reverseString(ref string s){
string temp = "";
for (int i = s.Length - 1; i >= 0; i--)
temp += s[i];
s = temp;
}
static void removeSpaces(ref string s){
string temp = "";
for (int i = 0; i < s.Length; i++)
if (s[i] != ' ')
temp += s[i];
s = temp;
}
}