Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1.     public class ColorArray
  2.     {
  3.         public Color[] Colors { get; set; }
  4.  
  5.         public int Width { get; set; }
  6.         public int Height { get; set; }
  7.  
  8.         public ColorArray()
  9.         {
  10.         }
  11.  
  12.         public ColorArray(int width, int height)
  13.         {
  14.             Width = width;
  15.             Height = height;
  16.             Colors = new Color[width * height];
  17.         }
  18.         public Color this[int index]
  19.         {
  20.             get
  21.             {
  22.                 return Colors[index];
  23.             }
  24.             set
  25.             {
  26.                 Colors[index] = value;
  27.             }
  28.         }
  29.  
  30.         public Color this[int x, int y]
  31.         {
  32.             get
  33.             {
  34.                 if (x < 0 || x >= Width || y < 0 || y >= Height)
  35.                 {
  36.                     throw new IndexOutOfRangeException();
  37.                 }
  38.                 return Colors[x + y * Height];
  39.             }
  40.             set
  41.             {
  42.                 if (x < 0 || x >= Width || y < 0 || y >= Height)
  43.                 {
  44.                     throw new IndexOutOfRangeException();
  45.                 }
  46.                 Colors[x + y * Height] = value;
  47.             }
  48.         }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement