Advertisement
Guest User

Untitled

a guest
May 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Drawing
  9. {
  10.     public delegate bool FindRectangle(Rectangle rectangle);
  11.  
  12.     public static class RectangleExtension
  13.     {
  14.         public static List<Rectangle> WhereContains(this List<Rectangle> rectangles, Point point)
  15.         {
  16.             List<Rectangle> resultList = new List<Rectangle>();
  17.  
  18.             foreach (var rectangle in rectangles)
  19.             {
  20.                 if (rectangle.Contains(point))
  21.                 {
  22.                     resultList.Add(rectangle);
  23.                 }
  24.             }
  25.  
  26.             return resultList;
  27.         }
  28.  
  29.         public static List<Rectangle> Where(this List<Rectangle> rectangles, FindRectangle findRectangleDelegate)
  30.         {
  31.             List<Rectangle> resultList = new List<Rectangle>();
  32.  
  33.             foreach (var rectangle in rectangles)
  34.             {
  35.                 if (findRectangleDelegate(rectangle))
  36.                 {
  37.                     resultList.Add(rectangle);
  38.                 }
  39.             }
  40.  
  41.             return resultList;
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement