怎么管理网站的内容吗,保定网站关键词优化,网络推广培训平台,网站开发域名注册接口#xff1a;描述可属于任何类或结构的一组相关功能#xff0c;通过interface关键字来声明#xff1b;接口只包含方法、委托或事件和属性的签名#xff08;接口包含的成员#xff09;、不能包含字段#xff08;因为字段是包含数据的#xff09;。方法的实现是“继承”…接口描述可属于任何类或结构的一组相关功能通过interface关键字来声明接口只包含方法、委托或事件和属性的签名接口包含的成员、不能包含字段因为字段是包含数据的。方法的实现是“继承”接口的类中完成的接口可以包含的成员的访问修饰符只能且默认为public一个接口可以从一个或多个基接口继承接口类似于抽象基类继承接口的任何非抽象类型都必须实现接口的所有成员当基类型列表包含基类和接口时基类必须是列表中的第一项实现接口的类可以显式实现该接口的成员显示实现的成员不能通过类实例访问而只能通过接口实例访问类和结构可以按照类继承基类或结构的类似方式继承接口但注意类或结构可继承多个接口类或结构继承接口时仅继承方法名称和签名因为接口本身不包含实现接口和接口成员是抽象的但不用写出abstract关键字接口不提供默认实现 接口是一种规划为你定义出一系列的规则和任务但不去实现它; 先看一个实例: interface IPoint{// Property signatures: int x {get;set; }int y {get;set; }}class Point : IPoint{// Fields: private int _x;private int _y;// Constructor: public Point(int x, int y) { _x x; _y y; }// Property implementation: public int x {get {return _x; }set { _x value; } }public int y {get {return _y; }set { _y value; } }}class MainClass{static void PrintPoint(IPoint p) { Console.WriteLine(x{0}, y{1}, p.x, p.y); }static void Main() { Point p new Point(2, 3); Console.Write(My Point: ); PrintPoint(p); }}// Output: My Point: x2, y3 上面是一个简单的接口实现,如果在一个Web网页上的.CS文件中继承一个接口,如下: 先定义接口: public interface Iuser{string UserName { set; get; }string Role { set; get; }string Age { set; get; }string Sex { set; get; }bool Userlogin(string Name,string PassWord);}新建一个页面Login.aspx,代码如下; bodyform idform1 runatserverdivtable classstyle1trtd classstyle2asp:Label IDlblUsername runatserver TextUsername/asp:Label/tdtdasp:TextBox IDtxtUserName runatserver/asp:TextBox/td/trtrtd classstyle2asp:Label IDlblPassWord runatserver TextPassWord/asp:Label/tdtdasp:TextBox IDtxtPassWord runatserver/asp:TextBox/td/trtrtd classstyle2/tdtdasp:Button IDbtnSubmit runatserver οnclickbtnSubmit_Click TextSubmit //td/trtrtd classstyle2/tdtdasp:Label IDlblMessage runatserver/asp:Label/td/tr/table/div/form
/bodyLogin.aspx.cs代码如下: public partial class Login : Iuser{protected void Page_Load(object sender, EventArgs e){}private string _Age;private string _Role;private string _Sex;private string _UserName;#region Iuser Memberspublic string Age{get{return _Age;}set{_Age value;}}public string Role{get{return _Role;}set{_Role value;}}public string Sex{get{return _Sex;}set{_Sex value;}}public string UserName{get{return _UserName;}set{_UserName value;}}public bool Userlogin(string Name, string PassWord){return true;}#endregionprotected void btnSubmit_Click(object sender, EventArgs e){if (Userlogin(txtUserName.Text, txtPassWord.Text)){lblMessage.Text login Successful!;SetUserInfo(txtUserName.Text);}else{lblMessage.Text Login fail!;}}protected void SetUserInfo(string Name){Age 25;Role Visit;Sex Man;UserName spring yang;}}然后新建一个UsingUser.cs类; 代码如下: public class UsingUser : WebPart, Iuser{private string _Age;private string _Role;private string _Sex;private string _UserName;#region Iuser Memberspublic string Age{get{return _Age;}set{_Age value;}}public string Role{get{return _Role;}set{_Role value;}}public string Sex{get{return _Sex;}set{_Sex value;}}public string UserName{get{return _UserName;}set{_UserName value;}}public bool Userlogin(string Name, string PassWord){return true;}#endregionprivate void AddControlToWebPart(){Type controlType Type.GetType(ASP.web_Login_aspx,webinterface, Version1.0.0.0, Cultureneutral, PublicKeyToken9f4da00116c38ec5);System.Web.UI.UserControl userControl (System.Web.UI.UserControl)this.Page.LoadControl(controlType, null);Iuser iuserProperty userControl as Iuser;Age iuserProperty.Age;Role iuserProperty.Role;Sex iuserProperty.Sex;UserName iuserProperty.UserName;this.Controls.Add(userControl);}}这样就可以调用页面内容的数据了,通过接口传递页面的数据就这样完成了,你可以在UsingUser.cs做你想要的操作了. 转载于:https://www.cnblogs.com/springyangwc/archive/2011/03/16/1986136.html