In this instance, you can use both typeof and GetType() to get the type of the parameter:
public class Foo<T>
{
private void Bar<TR>(T test1, TR test2)
{
var t1 = test1.GetType();
var t2 = test2.GetType();
var i = 5;
var ti = i.GetType();
}
}
That should be:
public class Foo<T>
{
private void Bar<TR>(T test1, TR test2)
{
var t1 = typeof(T);
var t2 = typeof(TR);
var i = 5;
var ti = typeof(int);
}
}
The reasoning being that if the generic is a value type, calling GetType() results in an unnecessary boxing of the value.
In this instance, you can use both
typeof
andGetType()
to get the type of the parameter:That should be:
The reasoning being that if the generic is a value type, calling
GetType()
results in an unnecessary boxing of the value.