generics - c# how can I compare type of template type to builtin type on runtime -



generics - c# how can I compare type of template type to builtin type on runtime -

that code doesn't compile, has thought how write logic correctly?

public void filbuff<t>(t p_tinput) { if(typeid(p_tinput )== typeof(string)) { m_bbuff = system.text.encoding.ascii.getbytes((string)p_tinput); } }

use typeof(t). this:

public void filbuff<t>(t p_tinput) { if(typeof(t) == typeof(string)) { m_bbuff = system.text.encoding.ascii.getbytes((string)p_tinput); } }

as aside, doing generics (not templates) little odd. might improve utilize overloaded method in case.

c# generics runtime

Comments

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -