Ok, suppose you define a delegate in some class.
public delegate void StringDelegate (string s);
and another class implements a method :
public static void StringWriter (string s) {...}
In the book that I'm reading "Programming C#" 4th ed they create delegates using the new keyword, ex:
ClassDelegate.StringDelegate writer;
writer = new ClassDelegate.StringDelegate (DelegateImplementer.StringWriter);
writer("Hello");
However, I see one can also call the delegate method this way
ClassDelegate.StringDelegate writer;
writer = DelegateImplementer.StringWriter;
writer ("Hello");
What's the difference? Why do I want instantiate and create an object delegate when I can just simply pass or make reference to the signature of the method delegate.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…