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 'new()' constraint cannot be used with the 'struct' constraint
When specifying constraints on the type of a generic, the new()
constraint may only be used with class type constraints, interface type constraints, reference type constraints, and type parameter constraints, but not with value type constraints.
The following sample generates CS0451.
// CS0451.cs
using System;
public class C4
{
public void F4<T>() where T : struct, new() {} // CS0451
}
// OK
public class C5
{
public void F5<T>() where T : struct {}
}
public class C6
{
public void F6<T>() where T : new() {}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: