Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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'
This error occurs when you pass a value type such as a struct
or int
as a parameter to a generic type or method that has a reference type constraint.
The following code generates error 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
.NET feedback
.NET is an open source project. Select a link to provide feedback: