次の方法で共有


コンパイラ エラー CS0080

更新 : 2007 年 11 月

エラー メッセージ

制約は非ジェネリック宣言では許可されません。

この構文は、ジェネリック宣言で、型パラメータに制約を適用する場合にのみ使用できます。詳細については、「ジェネリック (C# プログラミング ガイド)」を参照してください。

次の例では、MyClass クラスも Foo メソッドもジェネリックではないため、CS0080 エラーが生成されます。

namespace MyNamespace
{
    public class MyClass where MyClass : System.IDisposable // CS0080    //the following line shows an example of correct syntax
    //public class MyClass<T> where T : System.IDisposable
    {
        public void Foo() where Foo : new() // CS0080
        //the following line shows an example of correct syntax
        //public void Foo<U>() where U : struct
        {
        }
    }

    public class Program
    {
        public static void Main()
        {
        }
    }
}