Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Delegates
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] numbers = new int[] { 1, 2, 3, 4, 5 };
- Func<int, int> sum = x => x + 100; // except int and return int
- Func<int, int> multiply = x => x * 2;
- Action<int> print = x => Console.WriteLine(x); // except int, return always void
- foreach (var num in numbers)
- {
- Console.WriteLine(sum(num));
- var multiplyResult = multiply(num);
- print(multiplyResult);
- Console.WriteLine("--------------------");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment