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
Post a Comment