G
Guest
I’m just starting to learn delegates. I’m at the very beginning. If I understand correctly, delegates are for when you want to pass a function as a parameter. For example the client provides a custom function to be called in a provider class. My confusion is that you can already achieve this by interfaces and objects without delegates (which have a little more complicated syntax)
Here is an example without delegates. class Class1 and class MyProc are on the client side and class Special is on the provider side. In short what delegates have more
class Class
static void Main(string[] args
Special s = new Special()
MyProc mp = new MyProc()
s.PrintValues(mp)
class MyProc : Isa
public int proc (int a
return (a * 2)
interface Isa
int proc(int a)
class Special
private int a = 10
public void PrintValues(Isam o
Console.WriteLine("a processed value is " + o.proc(a))
}
Here is an example without delegates. class Class1 and class MyProc are on the client side and class Special is on the provider side. In short what delegates have more
class Class
static void Main(string[] args
Special s = new Special()
MyProc mp = new MyProc()
s.PrintValues(mp)
class MyProc : Isa
public int proc (int a
return (a * 2)
interface Isa
int proc(int a)
class Special
private int a = 10
public void PrintValues(Isam o
Console.WriteLine("a processed value is " + o.proc(a))
}