Construct a delegate using method group conversion : delegate « delegate « C# / CSharp Tutorial

C# / CSharp Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statement
5. String
6. struct
7. Class
8. Operator Overload
9. delegate
10. Attribute
11. Data Structure
12. Assembly
13. Date Time
14. Development
15. File Directory Stream
16. Preprocessing Directives
17. Regular Expression
18. Generic
19. Reflection
20. Thread
21. I18N Internationalization
22. GUI Windows Forms
23. 2D
24. Design Patterns
25. Windows
26. XML
27. ADO.Net
28. Network
29. Directory Services
30. Security
31. unsafe
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / CSharp Tutorial » delegate » delegate 
9. 1. 8. Construct a delegate using method group conversion
using System;
 
delegate string StrMod(string str)
 
class MainClass 

  static string replaceSpaces(string a) { 
    Console.WriteLine("replaceSpaces")
    return a; 
  }  
 
  static string removeSpaces(string a) { 
    Console.WriteLine("removeSpaces")
    return a; 
  }  
 
  static string reverse(string a) { 
    Console.WriteLine("reverseSpaces")
    return a; 
  
     

    public static void Main() {  
      
      StrMod strOp = replaceSpaces; // use method group conversion 
      string str; 
     
      // Call methods through the delegate. 
      str = strOp("This is a test.")
    
          
      strOp = removeSpaces; // use method group conversion 
      str = strOp("This is a test.")
    
     
      strOp = reverse; // use method group converison 
      str = strOp("This is a test.")
    }

}
replaceSpaces
removeSpaces
reverseSpaces
9. 1. delegate
9. 1. 1. Define a delegate with no return value and no parameters
9. 1. 2. Add both static and non-static function to a delegate
9. 1. 3. Delegate with reference paramemters
9. 1. 4. Delegate with return values
9. 1. 5. Use a delegate to call object methods
9. 1. 6. delegate is a function pointer
9. 1. 7. A simple delegate example.
9. 1. 8. Construct a delegate using method group conversion
9. 1. 9. Delegates can refer to instance methods
9. 1. 10. Delegates to Instance Members
9. 1. 11. uses the invocation list to calculate a factorial
w___w_w___.__ja_v__a_2_s__._c__o_m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.