c# - 修饰符 public 对此项目无效

标签 c#

我遇到了错误

the modifier public is not valid for this item

这是我的代码,请帮助我。

    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    public partial class First : System.Web.UI.Page,test 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = test1("Hi", 1).ToString();
        }

    }
    public class Base
    {
        public int test1(int x)
        {
            return x;
        }
        public string test1(string x)
        {
            return x;
        }
        public string test1(string x, int y)
        {
            return x + y;
        }
    }
    public interface test
    {
        public int test1(int x);
        public string test1(string x);
        public string test1(string x, int y);
    }

谢谢, 普拉迪普

最佳答案

你的接口(interface)声明应该是这样的:

public interface test
{
    int test1(int x);
    string test1(string x);
    string test1(string x, int y);
}

访问修饰符在 interface declarations 上无效:

Interfaces consist of methods, properties, events, indexers, or any combination of those four member types. An interface cannot contain constants, fields, operators, instance constructors, destructors, or types. It cannot contain static members. Interfaces members are automatically public, and they cannot include any access modifiers.

关于c# - 修饰符 public 对此项目无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3652717/

相关文章:

c# - 为什么不使用 Html.EditorForModel()

c# - 验证当前经过身份验证的 Windows 用户是否具有委派权限

c# - 我的 IEnumerable 是否应该枚举作为参数传递给 AddRange() 之类的方法的 IEnumerable?

c# - NancyFX - 自定义 404 处理程序覆盖每个 404 响应

c# - 文档未能生成多个操作单个操作

c# - 在 Windows Form APP 中打开 WPF 窗口

c# - 一个 RFC 调用正在返回数据,但另一个则没有

c# - 性能分析 asp.net,什么是 ProcessRequestNotificationHelper?

c# - 如何序列化一个 ViewState 对象

c# - .NET ToolStrip 标准图标的位置