The Method Group feature was mentioned in the previous proxy object initialization. The C # compiler can implicitly convert the method group to its compatible proxy object. For example:
[Csharp]
Feedback fbInstance = FeedbackToFile;
Method group is the name of a group of methods. It is called a method group because the method has the feature of overloading and each method name may have several signature values. For example:
[Csharp]
Void MyMethod ()
Void MyMethod (object sender, EventArgs e)
You can use MyMethod as the method group to assign values to the ThreadStart proxy object or EventHandler proxy object.
[Csharp]
ThreadStart x = MyMethod;
EventHandler y = MyMethod;
However, you cannot pass MyMethod as a parameter to an overloaded function that accepts ThreadStart and EventHandler as a parameter. The compiler will report an error that is ambiguous.
Similarly, you cannot implicitly convert a method group to an object of the System. Delegate type, because the compiler does not know which seed proxy type to use to create a proxy object. The solution is to use explicit type conversion.
[Csharp]
Delegate invalid = SomeMethod;
Delegate valid = (ThreadStart) SomeMethod;
In addition, the Method group can be used through the wrapper. For example, Control. Invoke only accepts the System. Delegate type as the parameter. Therefore, there are several ways to use Method group.
[Csharp]
Static void SimpleInvoke (Control control Control,
MethodInvoker invoker)
{Www.2cto.com
Control. Invoke (invoker );
}
...
SimpleInvoke (form, UpdateUI );
Form. Invoke (MethodInvoker) UpdateUI );
MethodInvoker invoker = UpdateUI;
Form. Invoke (invoker );