using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Project1
{
/enum Ccolor { RED, YELLOW }
interface shapes
{
Ccolor color { get; set; }
void Draw();
void Erase();
void Move();
}
struct Point1 : shapes/ /////////project1.Point1 不实现接口成员“project shapes.color”
{
public Ccolor color;
public int x, y;
public Ccolor Color
{
get { return color; }
set { color = value; }
}
public Point1(int x, int y)
{
this.x = x;
this.y = y;
this.color = Ccolor.RED;
}
public void Draw()
{
Console.WriteLine("绘制一个点");
}
public void Erase()
{
Console.WriteLine("擦拭一个点");
}
public void Move()
{
Console.WriteLine("移动一个点");
}
}
class Class1
{
public static void Main()
{
Point1 p1 = new Point1(1, 1);
Console.WriteLine("点的坐标是({0},{1})", p1.x, p1.y);
p1.Draw();
Console.ReadLine();
}
}
}
问题在代码中已经标注了
------解决思路----------------------
Ccolor color { get; set; }
和
public Ccolor Color
明显不是“实现”嘛。
------解决思路----------------------
改你的接口定义吧,改为
interface shapes
{
Ccolor Color { get; set; }
------解决思路----------------------
你接口定义的是属性,然后是小写的color,你实现中定义的是大写的属性Color
------解决思路----------------------
实现接口,成员签名要完全一致!
继承接口,可以使用visual studio的智能提示自动生成接口成员。