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

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -