Is there a way to use a keyword as a parameter? I wanted to make a method called BytesToValue()
, the way it would look is like this:
public static T BytesToValue<T>(byte[] buffer, T type)
{
string retType = typeof(T).ToString();
if (retType.Contains(".Byte"))
{
// code here.
}
else if (retType.Contains(".Int16"))
{
// code here.
}
// and so on with all other types.
}
I wanted the T type
parameter to accept just a keyword e.g. BytesToValue(new byte[] { 0, 0, 0, 0 }, float)
, Is there a way to use keywords as parameters? I know the example wont work but is there a way to make it work? If not then what should i do?