Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0265

Partial declarations of 'type' have inconsistent constraints for type parameter 'type parameter'

This error happens when you define a generic class as a partial class, so that its partial definitions occur in more than one place, and the constraints on the generic type are inconsistent or different in two or more places. If you specify the constraints in more than one place, they must all be identical. The easiest solution is to specify the constraints in one place, and omit them everywhere else. For more information, see Partial Classes and Methods (C# Programming Guide) and Constraints on Type Parameters (C# Programming Guide).

The following code generates error CS0265.

In this code, the partial class definitions are all in a single file, but they could also be spread across multiple files.

// CS0265.cs
public class GenericsErrors 
    interface IFace1 { }
    interface IFace2 { }
    partial class PartialBadBounds<T> where T : IFace1 { } // CS0265
    partial class PartialBadBounds<T> where T : IFace2 { } 

Community Additions

© 2014 Microsoft