the modifier public is not valid for this item
I am getting error
the modifier public is not valid for this item
this my code, please help me.
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;
开发者_JAVA技巧 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);
}
Thanks, Pradeep
Your interface declaration should look like this:
public interface test
{
int test1(int x);
string test1(string x);
string test1(string x, int y);
}
Access modifiers are not valid on 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.
Omit the "public" keyword from your interface method declarations. That's not valid, interfaces always have public accessibility.
Defining these methods in the Base class isn't good enough either. Either let the Base class inherit "test" or move the methods to First.
Declaring the Page_Load event handler protected is fishy too, it ought to be private since overriding it isn't possible and calling it directly from a class derived from First would normally be a mistake.
精彩评论