更新:2007 年 11 月

错误消息

两个分部方法声明都必须是扩展方法,或者都不能是扩展方法。

分部方法由定义声明(签名)和可选的实现声明(体)组成。如果定义声明为扩展方法,则实现声明(如果定义)也必须为扩展方法。同样,如果定义方法不是扩展方法,则实现方法也不能为扩展方法。

更正此错误

  • 从其中一部分中移除 this 修饰符,或将该修饰符添加到另一部分中。

示例

下面的示例生成 CS0755:

 复制代码
// cs0755.cs
    public static partial class Ext
    {
        static partial void Part(this C c); //Extension method

        // Typically the implementing declaration is in a separate file.
        static partial void Part(C c) //CS0755
        {
        }
    }

    public partial class C
    {
        public static int Main()
        {
            return 1;
        }
    }

请参见

参考

扩展方法(C# 编程指南)