title: Array and indexer in generic class
body: <p>Up until now I've always been able to get an answer from an existing post on this site but today I have a question no one asked before it seems.</p>
  
  <p>Its about the follow piece of code:</p>
  
  <pre><code>class Board&lt;T&gt;
  {
      private T[,] board;
  
      public T[,] BoardArray
      {
          get { return (T[,])board.Clone(); }
      }
  
      public T this[int y, int x]
      {
          get { return board[y, x]; }
          set { board[y, x] = value; }
      }
  
      public Board()
      {
          board = new T[8, 8];
      }
  
      public void AssignToBoard()
      {
          board[1, 2] = 3;
          this[1, 2] = 3;
      }
  }
  </code></pre>
  
  <p>The problem is that both lines of code in the method generate the same compile-time error. I know why the error is thrown but I don't know a clean work-around.
  This is the error:</p>
  
  <pre><code>Error   1   Cannot implicitly convert type 'int' to 'T' C:\Users\Peter\Desktop\Dropbox\ReversieAI\ReversieAI\ReversieAI\Map.cs  31  18  ReversieAI
  </code></pre>
  
  <p>The only way I've been able to get my code compiled is to change the lines to:</p>
  
  <pre><code>board[1, 2] = (T)(object)3;
  this[1, 2] = (T)(object)3;
  </code></pre>
  
  <p>Although it works, it is still a dirty solution. Do any of you guys recognize the problem and can help me/share any thoughts?</p>
  
  <p>Thanks in advance,
  Peter</p>
  
  <p>Edit: I have found a solution by changing something in my architecture that removes the generic part of the class. Thank you for all your feedback. I really appreciate it.</p>