Reputation: 715
that code doesn't compile, anyone has any idea how to write this 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);
}
}
Upvotes: 0
Views: 65
Reputation: 141638
Use typeof(T)
. Like this:
public void FilBuff<T>(T p_tInput)
{
if(typeof(T) == typeof(string))
{
m_bBuff = System.Text.Encoding.ASCII.GetBytes((string)p_tInput);
}
}
As an aside, what you are doing with generics (not templates) is a little odd. It might be better to just use an overloaded method in your case.
Upvotes: 4