title: Generic for unsafe: T[,] and T[,,] - C# 7.3+
body: <p>I run c# 7.3 so please no comments like 'this will never work'</p>
  
  <p>I have 2 Classes with a common interface:
  Image2D and Image3D and the Common Interface Image</p>
  
  <pre><code>public interface IImage&lt;T, S&gt; where T : unmanaged {
    long Length { get; }
    S Data { get; }
    T GetMaxTypeValue();
    T GetMinTypeValue(); 
  }
  
  public abstract class I2D&lt;T&gt; : IImage&lt;T, T[,]&gt; where T : unmanaged {
      public int LengthX { get; }
      public int LengthY { get; }
  
      public T[,] Data { get; }
      ...
  }
  
  
  public abstract class I3D&lt;T&gt; : IImage&lt;T, T[,,]&gt; where T : unmanaged {
      public int LengthX { get; }
      public int LengthY { get; }
      public int LengthZ { get; }
  
      public T[,,] Data { get; }
      ....
  }
  </code></pre>
  
  <p>What I am trying to do now: No matter if the input is of type I3D or I2D i need unsafe access on the Data array...</p>
  
  <pre><code>public static unsafe T Smth&lt;T, S&gt;(IImage&lt;T, S&gt; image) where T : unmanaged where S : unmanaged {
      var data = image.Data;
  
      fixed (T* pData = data) {
          do someting
      }
      return ...
  }
  </code></pre>
  
  <p>This, of course, does not work: 'Can not convert initializer type S to type T*' which makes sense... But how Can I get the datatype of the arrays? Is there a better way to solve this problem?</p>