Guest User

Untitled

a guest
Nov 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. public class TestAction1
  2. {
  3. public static void Main()
  4. {
  5. Action<string> messageTarget;
  6.  
  7. if (Environment.GetCommandLineArgs().Length > 1)
  8. messageTarget = ShowWindowsMessage;
  9. else
  10. messageTarget = Console.WriteLine;
  11.  
  12. messageTarget("Hello, World!");
  13. }
  14.  
  15. private static void ShowWindowsMessage(string message)
  16. {
  17. MessageBox.Show(message);
  18. }
  19. }
  20.  
  21. public class TestAction1
  22. {
  23. public static void Main()
  24. {
  25. if (Environment.GetCommandLineArgs().Length > 1)
  26. MessageBox.Show("Hello, World!");
  27. else
  28. Console.WriteLine("Hello, World!");
  29. }
  30. }
  31.  
  32. public class TestLambdaExpression
  33. {
  34. public static void Main()
  35. {
  36. Action<string> messageTarget;
  37.  
  38. if (Environment.GetCommandLineArgs().Length > 1)
  39. messageTarget = s => ShowWindowsMessage(s);
  40. else
  41. messageTarget = s => Console.WriteLine(s);
  42.  
  43. messageTarget("Hello, World!");
  44. }
  45.  
  46. private static void ShowWindowsMessage(string message)
  47. {
  48. MessageBox.Show(message);
  49. }
  50. }
  51.  
  52. public class TestLambdaExpression
  53. {
  54. public static void Main()
  55. {
  56. if (Environment.GetCommandLineArgs().Length > 1)
  57. MessageBox.Show("Hello, World!");
  58. else
  59. Console.WriteLine("Hello, World!");
  60. }
  61. }
  62.  
  63. class Program
  64. {
  65. static void Main()
  66. {
  67. List<String> names = new List<String>();
  68. names.Add("Bruce");
  69. names.Add("Alfred");
  70. names.Add("Tim");
  71. names.Add("Richard");
  72.  
  73. // Display the contents of the list using the Print method.
  74. names.ForEach(Print);
  75.  
  76. // The following demonstrates the anonymous method feature of C#
  77. // to display the contents of the list to the console.
  78. names.ForEach(delegate(String name)
  79. {
  80. Console.WriteLine(name);
  81. });
  82. }
  83.  
  84. private static void Print(string s)
  85. {
  86. Console.WriteLine(s);
  87. }
  88. }
  89.  
  90. class Program
  91. {
  92. static void Main()
  93. {
  94. List<String> names = new List<String>();
  95. names.Add("Bruce");
  96. names.Add("Alfred");
  97. names.Add("Tim");
  98. names.Add("Richard");
  99. foreach (var name in names) {
  100. Console.WriteLine(name);
  101. }
  102. foreach (var name in names)
  103. {
  104. Console.WriteLine(name);
  105. }
  106. }
  107. }
Add Comment
Please, Sign In to add comment