c# - Is there anyway to specify the possible types for a generic class? -


i'm trying write code xna have own drawing modules can use cache/draw static vertices/indices.

here's class, line in question giving me trouble line 51.

_vertexbuffer.setdata(_vertices.toarray()); 

it has error: the type 't' must non-nullable value type in order use parameter 't'

it doesn't seem setdata expects array of vertices matches vertexdeclaration used in vertexbuffers constructor, whilst definition of list/class says can type.

is there anyway specify <t> vertices?

they called generic type constraints. whatever vertexbuffer type is, has on method:

void setdata<t>(...) t : struct 

this causing error.

in fact, msdn says method signature:

public void setdata<t> (      t[] data ) t : valuetype 

which same.

so, fix this, you'll have pass in array of items value types, not reference types. is, instantiation of drawmodule<t> must drawmodule<valuetypehere>.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -