title: C# abstract struct
body: <p>How can I achieve inheritance (or similar) with structs in C#?
  I know that an abstract struct isn't possible, but I need to achieve something similar.</p>
  
  <p>I need it as a struct because it has to be a value type. And I need inheritance because I need a generic array and methods that I can garantee are there.</p>
  
  <p>I think an example will go a long way, so heres some code that won't compile, but shows what I want to achieve;</p>
  
  <pre><code>    abstract struct Vertex
      {
         abstract int SizeInBytes;
         abstract void SetPointers();
      }
      struct ColorVertex : Vertex
      {
         Vector3 Position;
         Vector4 Color;
  
         override int SizeInBytes //static
         {
            get { return (3 + 4) * 4; }
         }
         override void SetVertexPointers() //static
         {
             ...
         }
      }
  
  class main
  {
     static void main()
     {
        Vertex[] verts = new Vertex[3];
        for(int i = 0; i &lt; 3; i++)
            verts[i] = new ColorVertex();
  
        verts[0].SetVertexPointers(); //should call ColorVertex.SetVertexPointers
  
        externalAPIcall(verts);
     }
  }
  </code></pre>
  
  <p>EDIT: </p>
  
  <p>The reason I need value types is so that I can make an array of them, and pass it to OpenGL as a vertex buffer. For this, the data needs to be directly contained in this array.</p>
  
  <p>I'd be surprised if this were simply not possible to achieve.</p>