Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- public void Main()
- {
- Program.Try(Program.HandleArray_Where, "array.where");
- Program.Try(Program.HandleArray_Where_OrderBy, "array.where.orderby");
- Program.Try(Program.HandleList_Where, "list.where");
- Program.Try(Program.HandleList_Where_OrderBy, "list.where.orderby");
- }
- private static void Try(Action action, string text)
- {
- Console.WriteLine(text);
- try
- {
- action.Invoke();
- }
- catch (InvalidOperationException)
- {
- Console.WriteLine("Invalid operation");
- }
- Console.WriteLine();
- Console.WriteLine();
- }
- private static void HandleArray_Where()
- {
- IList<int> arr = new[] { 1, 2, 3, 4, 5 };
- var enumerable = arr.Where(item => item > 2);
- foreach (var item in enumerable)
- {
- arr[3] = 0;
- Console.WriteLine(item);
- }
- }
- private static void HandleArray_Where_OrderBy()
- {
- IList<int> arr = new[] { 1, 2, 3, 4, 5 };
- var orderedEnumerable = arr.Where(item => item > 2).OrderBy(asd => asd);
- foreach (var item in orderedEnumerable)
- {
- arr[3] = 0;
- Console.WriteLine(item);
- }
- }
- private static void HandleList_Where()
- {
- IList<int> list = new List<int> { 1, 2, 3, 4, 5 };
- var enumerable = list.Where(item => item > 2);
- foreach (var item in enumerable)
- {
- list[3] = 0;
- Console.WriteLine(item);
- }
- }
- private static void HandleList_Where_OrderBy()
- {
- IList<int> list = new List<int> { 1, 2, 3, 4, 5 };
- var orderedEnumerable = list.Where(item => item > 2).OrderBy(asd => asd);
- foreach (var item in orderedEnumerable)
- {
- list[3] = 0;
- Console.WriteLine(item);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement