
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 展开
(1)定义接口IPoint,IPoint中定义2个属性 x,y,以及printInfo方法。
(2)在类Point中实现接口中定义的属性和方法。
(3)在主程序中定义Point的对象,并在屏幕中输出x,y 展开
1个回答
展开全部
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());
}
}
{
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());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询