Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestAction1
- {
- public static void Main()
- {
- Action<string> messageTarget;
- if (Environment.GetCommandLineArgs().Length > 1)
- messageTarget = ShowWindowsMessage;
- else
- messageTarget = Console.WriteLine;
- messageTarget("Hello, World!");
- }
- private static void ShowWindowsMessage(string message)
- {
- MessageBox.Show(message);
- }
- }
- public class TestAction1
- {
- public static void Main()
- {
- if (Environment.GetCommandLineArgs().Length > 1)
- MessageBox.Show("Hello, World!");
- else
- Console.WriteLine("Hello, World!");
- }
- }
- public class TestLambdaExpression
- {
- public static void Main()
- {
- Action<string> messageTarget;
- if (Environment.GetCommandLineArgs().Length > 1)
- messageTarget = s => ShowWindowsMessage(s);
- else
- messageTarget = s => Console.WriteLine(s);
- messageTarget("Hello, World!");
- }
- private static void ShowWindowsMessage(string message)
- {
- MessageBox.Show(message);
- }
- }
- public class TestLambdaExpression
- {
- public static void Main()
- {
- if (Environment.GetCommandLineArgs().Length > 1)
- MessageBox.Show("Hello, World!");
- else
- Console.WriteLine("Hello, World!");
- }
- }
- class Program
- {
- static void Main()
- {
- List<String> names = new List<String>();
- names.Add("Bruce");
- names.Add("Alfred");
- names.Add("Tim");
- names.Add("Richard");
- // Display the contents of the list using the Print method.
- names.ForEach(Print);
- // The following demonstrates the anonymous method feature of C#
- // to display the contents of the list to the console.
- names.ForEach(delegate(String name)
- {
- Console.WriteLine(name);
- });
- }
- private static void Print(string s)
- {
- Console.WriteLine(s);
- }
- }
- class Program
- {
- static void Main()
- {
- List<String> names = new List<String>();
- names.Add("Bruce");
- names.Add("Alfred");
- names.Add("Tim");
- names.Add("Richard");
- foreach (var name in names) {
- Console.WriteLine(name);
- }
- foreach (var name in names)
- {
- Console.WriteLine(name);
- }
- }
- }
Add Comment
Please, Sign In to add comment