Information Technology Reference
In-Depth Information
delegate void MyDel(int x); // Declare delegate type.
MyDel delVar, dVar; // Create delegate variables.
Instance method
delVar = new MyDel( MyInstObj.MyM1 ); // Create delegate and save ref.
dVar = new MyDel( SClass.OtherM2 ); // Create delegate and save ref.
Static method
Figure 15-3. Instantiating the delegates
Besides allocating the memory for the delegate, creating a delegate object also places the
first method in the delegate's invocation list. You can also create the variable and instantiate
the object in the same statement, using the initializer syntax. For example, the following state-
ments produce the same configuration shown earlier, in Figure 15-3.
MyDel delVar = new MyDel( MyInstObj.MyM1 );
MyDel dVar = new MyDel( SClass.OtherM2 );
The following statements use the shortcut syntax, but again, produce the results shown in
Figure 15-3.
MyDel delVar = MyInstObj.MyM1;
MyDel dVar = SClass.OtherM2;
Search WWH ::




Custom Search