实验目的 :
练习C#中接口的作用
实验内容
1.声明一个接口IPlayer,包含五个接口方法:播放,停止,暂停,上一首和下一首(简单用label标签输出即可)。
2.声明一个接口IUsb,包含两个接口方法:接受,输出。
3.声明一个类MobilePhone,包含属性和方法,由同学自己决定
4.声明一个类IPhone继承MobilePhone类和两个接口IPlayer,IUsb。
一、核心代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
IPhone d = new IPhone("IPhone手机");
class MobilePhone
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
public MobilePhone(string name)
{
this.name = name;
}
public string phone()
{
return "打电话";
}
}
class IPhone : MobilePhone, IUsb, IPlyer
{
public IPhone(string Name) : base(Name) { }
new public string phone()
{
return "打电话";
}
public string music()
{
return "听音乐";
}
public string game()
{
return "看电影";
}
public string Input()
{
return "输入数据";
}
public string Output()
{
return "输出数据";
}
public string Play()
{
return "正在播放";
}
public string Stoy()
{
return "停止播放";
}
public string Pause()
{
return "暂停播放";
}
public string Pre()
{
return "上一首";
}
public string Next()
{
return "下一首";
}
}
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "名字:" + d.Name + "<br/>功能:" + d.phone() + " " + d.music() + " " + d.game();
}
protected void Button2_Click(object sender, EventArgs e)
{
Label2.Text = d.Output();
}
protected void Button3_Click(object sender, EventArgs e)
{
Label3.Text = d.Play();
}
protected void Button4_Click(object sender, EventArgs e)
{
Label3.Text = d.Stoy();
}
protected void Button5_Click(object sender, EventArgs e)
{
Label3.Text = d.Pause();
}
protected void Button6_Click(object sender, EventArgs e)
{
Label3.Text = d.Pre();
}
protected void Button7_Click(object sender, EventArgs e)
{
Label3.Text = d.Next();
}
protected void Button1_Click1(object sender, EventArgs e)
{
Label2.Text = d.Input();
}
}
interface IUsb
{
string Input();
string Output();
}
interface IPlyer
{
string Play();
string Stoy();
string Pause();
string Pre();
string Next();
}
二、实验结果: