初学接口遇到的问题~~

来源:百度知道 编辑:UC知道 时间:2024/05/13 05:20:19
调试不成功,老提示说:“ConsoleApplication6.A”不会实现接口成员。。
很费解!帮忙看看 谢谢!

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication6
{
interface IGetString
{
string gerString();
}
class A : IGetString
{
public string getString()
{
return "类A";
}
}
class B : IGetString
{
public string getString()
{
return "类B";
}
}
class C : IGetString
{
public string getString()
{
return "类C";
}
}

class Program

{

static void Main(string[] args)
{

A a = new A();
B b = new B();
C c = new C();

老问题:
interface IGetString
{
string gerString(); // ger 写错了
}

写错了,应该是 string getString();

你写的是什么 看不懂

我忘了 好像是子类重写 接口方法不用访问修饰符
要不就是

接口对象指向其子类对象 好像不用强制转换

也没必要用接口对象指向子类对象