Why does generic method with constraint of T: class result in boxing? [duplicate]
问题 This question already has answers here : Boxing when using generics in C# (2 answers) Closed 10 months ago . Why a generic method which constrains T to class would have boxing instructions in the generates MSIL code? I was quite surprised by this since surely since T is being constrained to a reference type the generated code should not need to perform any boxing. Here is the c# code: protected void SetRefProperty<T>(ref T propertyBackingField, T newValue) where T : class { bool isDifferent =