Edit

Share via


Compiler Error CS0453

The type 'Type Name' must be a non-nullable value type in order to use it as parameter 'Parameter Name' in the generic type or method 'Generic Identifier'

This error occurs when you use a non-value type argument in instantiating a generic type or method that has the value constraint on it. It can also occur when you use a nullable value type argument. See the last two lines of code in the following example.

Example

The following code generates this error.

// CS0453.cs  
using System;  
public class HV<S> where S : struct { }

// CS0453: string is not a value type
public class H1 : HV<string> { }

// CS0453: H1 is a class, not a struct
public class H2 : HV<H1> { }

// CS0453: HV is based on a class, not a struct
public class H3<S> : HV<S> where S : class { }
public class H4<S> : HV<S> where S : struct { } // OK

// CS0453: HV accepts a nullable int type
public class H4 : HV<int?> { }

// CS0453: HV is based on Nullable type of int
public class H5 : HV<Nullable<Nullable<int>>> { }

See also