简单的interface显式和隐式的实现

时间:2022-10-29 23:47:19
简单的interface显式和隐式的实现

一,新建接口

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; /// <summary>
/// InterF 的摘要说明
/// </summary> public interface Itest
{
string show(); string display();
}

二,新建接口实现类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; /// <summary>
/// test 的摘要说明
/// </summary>
public class test :Itest
{
public string show()
{
return "隐式实现接口";
} string Itest.display()
{
return "显式实现接口";
}
}

三,调用实现

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class Mytest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Itest a = new test();
Label1.Text = a.show();
Label2.Text = a.display();
}
}