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
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error CS0265 

Error Message

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 Class Definitions (C# Programming Guide) and Constraints on Type Parameters (C# Programmers Reference).

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

© 2015 Microsoft