M
muler
hi all,
Can anyone explain (possibly with examples) any special uses of
delegate combinations or removals?
In the very simple example below all delegate combinations/removals can
be done with delegate assignments. So what's the use of having them
around?
delegate string D(string str);
static string f1(string str)
{
return str.ToUpper();
}
static string f2(string str)
{
return str.ToLower();
}
static void Main(string[] args)
{
D d1 = new D(f1);
D d2 = new D(f2);
Console.WriteLine(d1("MuluGeta")); //outputs: MULUGETA
Console.WriteLine(d2("MuluGeta")); //outputs: mulugeta
d1 += d2 + d1 + d1 + d2; // same as d1 = d2 ?
// last is d2, so this outputs: mulugeta
Console.WriteLine(d1("MuluGeta"));
// removes d2, thus next output is: MULUGETA
d1 -= d2;
Console.WriteLine(d1("MuluGeta"));
}
I appreciate your comments/ideas.
Thanks in advance.
Can anyone explain (possibly with examples) any special uses of
delegate combinations or removals?
In the very simple example below all delegate combinations/removals can
be done with delegate assignments. So what's the use of having them
around?
delegate string D(string str);
static string f1(string str)
{
return str.ToUpper();
}
static string f2(string str)
{
return str.ToLower();
}
static void Main(string[] args)
{
D d1 = new D(f1);
D d2 = new D(f2);
Console.WriteLine(d1("MuluGeta")); //outputs: MULUGETA
Console.WriteLine(d2("MuluGeta")); //outputs: mulugeta
d1 += d2 + d1 + d1 + d2; // same as d1 = d2 ?
// last is d2, so this outputs: mulugeta
Console.WriteLine(d1("MuluGeta"));
// removes d2, thus next output is: MULUGETA
d1 -= d2;
Console.WriteLine(d1("MuluGeta"));
}
I appreciate your comments/ideas.
Thanks in advance.