You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.The text was updated successfully, but these errors were encountered: