Is there boxing when generic classes get structs with interface constraint ?

Hi,

Supposing there are these struct/class/interface:

---------------------------------------------------
interface Iface
{
void Method();
}

struct SomeStruct : Iface
{
public void Method()
{
}
}

class GenClass<T> where T : Iface
{
public void GenMethod(T t)
{
t.Method();
}
}
----------------------------------------------------

If I instantiate GenClass by passing 'SomeStruct' as generic argument, will there be boxing involved when calling SomeStruct's Method inside GenClass's GenMethod


Answer this question

Is there boxing when generic classes get structs with interface constraint ?

  • Don A

    No, there will be no boxing. That was one of the main design goals of Generics.

  • Is there boxing when generic classes get structs with interface constraint ?