title: Find largest area using
body: <p>I need to find largest area with same numbers in 2D array. Example: {{<strong>2</strong> <strong>2</strong> 3}{1 <strong>2</strong> 3}{1 <strong>2</strong> 1}}</p>
  
  <p>And mark it in new 2D array with same number for same area.</p>
  
  <p>I will need to color the table with 3 colors, so i use between 1-3 in table[,]</p>
  
  <p>I did test, but it doesn't work properly. ID just stacks too much on the same area.</p>
  
  <p>Second edit: updated the code</p>
  
  <pre><code>public class Matrix
  {
      public int Height { get; set; }
      public int Witdh { get; set; }
      public int[,] Table { get; set; }
      public int[,] Area { get; set; }
      public int ID { get; set; }
      public int tempBiggestArea = 0;
      public int biggestArea { get; set; }
      public Matrix(int height, int witdh)
      {
          Table = GenerateTable(height, witdh);
          Height = height;
          Witdh = witdh;
          ID = 2;
          Area = new int[height,witdh];
      }
      public int[,] GenerateTable(int height, int witdh)
      {
          int[,] table = new int[height, witdh];
          Random rnd = new Random();
          for (int i = 0; i &lt; table.GetLength(0); i++)
          {
              for (int j = 0; j &lt; table.GetLength(1); j++)
              {
                  table[i, j] = rnd.Next(3) + 1;
              }
          }
          return table;
      }
      public void Find(int x, int y, int color)
      {
  
          if (y &lt; 0)
              y = Height - 1;
  
          if (x &lt; 0)
              x = Witdh - 1;
  
          if (IsChanged(x, y))
              return;
  
          if (Area[x, y] == 0)
          {
              if (color &gt; 3)
                  color = 1;
  
              if (Table[x, y] == color)
              {
                  Area[x, y] = ID;
                  tempBiggestArea++;
                  Find(x, y - 1, color);
                  Find(x - 1, y, color);
                  ID++;
              }
          }
          if (tempBiggestArea &gt; biggestArea)
              biggestArea = tempBiggestArea;
          tempBiggestArea = 0;
          Find(x, y, color + 1);
      }
      public bool IsChanged(int i, int j)
      {
          return Area[i, j] != 0;
      }
  </code></pre>