Use the delegate expression and anonymous method in C # To implement the delegate Method

Source: Internet
Author: User
  1. Using system;
  2. Using system. Collections. Generic;
  3. Using system. LINQ;
  4. Using system. text;
  5. Namespace CSHARP Basics
  6. {
  7. Class delegate expression
  8. {
  9. Delegate bool extends smynumber (INT num );
  10. Public static void printmyrenumber (datagsmynumber del)
  11. {
  12. Console. writeline (DEL ());
  13. }
  14. Public static void main ()
  15. {
  16. // Anonymous method call
  17. Repeated smynumber MYDEL = delegate (INT num)
  18. {
  19. If (Num> 10)
  20. {
  21. Return true;
  22. }
  23. Else
  24. {
  25. Return false;
  26. }
  27. };
  28. Console. writeline ("anonymous method call: {0}", MYDEL (50 ));
  29. // Call with a delegate expression
  30. Repeated smynumber mydel2 = num => num> 10;
  31. Console. writeline ("using delegate expression {0}", mydel2 (50 ));
  32. Console. Read ();
  33. }
  34. }
  35. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.