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

    Question

  • 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 ?
    Saturday, June 10, 2006 12:59 AM

Answers

  • No, there will be no boxing.  That was one of the main design goals of Generics.
    Saturday, June 10, 2006 4:33 AM
    Moderator