C# 编程 接口问题

4.接口练习(1)定义接口IPoint,IPoint中定义2个属性x,y,以及printInfo方法。(2)在类Point中实现接口中定义的属性和方法。(3)在主程序中定... 4. 接口练习
(1)定义接口IPoint,IPoint中定义2个属性 x,y,以及printInfo方法。
(2)在类Point中实现接口中定义的属性和方法。
(3)在主程序中定义Point的对象,并在屏幕中输出x,y
展开
 我来答
xyhuju
2011-12-22 · TA获得超过127个赞
知道答主
回答量:124
采纳率:0%
帮助的人:155万
展开全部
public interface IPoint
{
int x { get; set; }
int y { get; set; }
string PrintInfo();
}

public class PrintPoint:IPoint
{
public int x { get; set; }
public int y { get; set; }

public string PrintInfo()
{
return string.Format("({0},{1})", x.ToString(), y.ToString());
}
}

class Test
{
static void Main()
{
PrintPoint p = new PrintPoint();
System.Console.Write("x: ");
p.x = int.Parse(System.Console.ReadLine());
System.Console.Write("y: ");
p.y = int.Parse(System.Console.ReadLine());
p.PrintInfo();

System.Console.WriteLine(p.PrintInfo());

}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式