Errore del compilatore CS0452

Aggiornamento: novembre 2007

Messaggio di errore

Il tipo 'nome tipo' deve essere un tipo reference per essere utilizzato come parametro 'nome parametro' nel metodo o nel tipo generico 'identificatore di oggetto generico'.
The type 'type name' must be a reference type in order to use it as parameter 'parameter name' in the generic type or method 'identifier of generic'

Questo errore si verifica quando un tipo di valore, ad esempio struct o int, viene passato come parametro a un metodo o a un tipo generico su cui è definito un vincolo di tipo reference.

Esempio

Il seguente codice di esempio genera l'errore CS0452.

// CS0452.cs
using System;
public class BaseClass<S> where S : class { }
public class Derived1 : BaseClass<int> { } // CS0452
public class Derived2<S> : BaseClass<S> where S : struct { } // CS0452