【问题标题】:Error 1 The modifier 'abstract' is not valid for this item错误 1 ​​修饰符 'abstract' 对该项目无效
【发布时间】:2012-07-17 00:53:10
【问题描述】:

我正在尝试构建我的 C# 项目,但出现错误:

The modifier 'abstract' is not valid for this item

在以下界面中:

namespace program.Drawing.Fields
{
    using System;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;

    public interface IFieldHolder
    {
        abstract event FieldChangedEventHandler FieldChanged;

        void AddField(Field field);
        Field GetField(FieldType fieldType);
        List<Field> GetFields();
        bool HasField(FieldType fieldType);
        void RemoveField(Field field);
        void SetFieldValue(FieldType fieldType, object value);
    }
}

项目: 字段已更改;

The modifier 'abstract' is not valid for this item

【问题讨论】:

  • @Matthew:他的界面没有定义任何字段...
  • 问题是什么?删除 abstract 可以解决问题。

标签: c# .net interface abstract


【解决方案1】:

根据定义,接口是抽象的,因为实现类必须实现它们。您不能在其中使用 abstract 关键字。 (范围界定也是如此)

【讨论】:

    【解决方案2】:

    我不确定您在此处尝试做什么,但您可能会发现以下信息很有帮助:

    “接口和接口成员是抽象的;接口不提供默认实现。”

    Interfaces (C# Programming Guide)

    也就是说,接口的成员是隐式抽象的。

    【讨论】:

      猜你喜欢
      • 2011-07-30
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      相关资源
      最近更新 更多