首页 新闻 赞助 找找看

c#关于接口的问题

0
[已解决问题] 解决于 2008-09-16 11:53

定义一个接口:

public interface Tinterface
{
  Tinterface Test(byte[] Arrbyte); 
}

 

实现:

public class T:Tinterface
{
    T Test(byte[] arr)
    {
        return this;
    }
}

 

在public class T:Tinterface 中'T'的地方报错

 

Error 1 'T' does not implement interface member 'Tinterface.Test(byte[])'. 'T.Test(byte[])' cannot implement an interface member because it is not public. E:\练习\WebSite22\App_Code\T.cs 16 14 E:\练习\WebSite22\

 

Fly-Sun的主页 Fly-Sun | 初学一级 | 园豆:200
提问于:2008-09-16 10:51
< >
分享
最佳答案
0

public class T : TInterface

{

    TInterface Test(byte[] Arrbyte)

    {

        return this;

    }

}

方法签名,包括返回值和参数都必须一模一样,你的T类的Test方法返回了T而不是TInterface,因此不行,在接口的实现的时候是没有协变的

Gray Zhang | 专家六级 |园豆:17610 | 2008-09-16 11:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册