我遇到了错误
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/