Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0310

The type 'typename' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'parameter' in the generic type or method 'generic'

The generic type or method defines a new constraint in its where clause, so any type must have a public parameterless constructor in order to be used as a type argument for that generic type or method. To avoid this error, make sure that the type has the correct constructor, or modify the constraint clause of the generic type or method.

The following sample generates CS0310:

// CS0310.cs
using System;

class G<T> where T : new()
    T t;

    public G()
        t = new T();

class B
    private B() { }
    // Try this instead:
    // public B() { }

class CMain
    public static void Main()
        G<B> g = new G<B>();   // CS0310
© 2015 Microsoft