Suppose we have:
interface Foo
{
bool Func(int x);
}
class Bar: Foo
{
bool Func(int x)
{
return (x>0);
}
}
class Baz: Foo
{
bool Func(int x)
{
return (x<0);
}
}
Now we can toss around Bar and Baz as a Foos and call their Func methods.
Delegates simplify this a little bit:
delegate bool Foo(int x);
bool Bar(int x)
{
return (x<0);
}
bool Baz(int x)
{
return (x>0);
}
Now we can toss around Bar and Baz as Foo delegates.
What is the real benefit of delegates, except for getting shorter code?