Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Linq;
- namespace IMJunior
- {
- class Program
- {
- delegate bool Predicate(string item);
- delegate string Predicate2(string item);
- static void Main()
- {
- string[] words = { "Hello", "Temp", "Some", "Hesus" };
- foreach (var word in Where(words, (x) => x.StartsWith("H")))
- {
- Console.WriteLine(word);
- }
- }
- static void Foreach(string[] array, Predicate2 predicate)
- {
- List<string> result = new List<string>();
- foreach (var item in array)
- {
- result.Add(predicate(item));
- }
- array = result.ToArray();
- }
- static string[] Where(string[] array, Predicate predicate)
- {
- List<string> result = new List<string>();
- foreach (var item in array)
- {
- if (predicate(item))
- {
- result.Add(item);
- }
- }
- return result.ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement