C# &引用;修改器public对此项无效";关于接口方法
好的,因此我在从Interface(显示数据的windows窗体)调用GetClassAverage()方法时遇到问题。我也得到了下面的错误 “公共修饰符对此项无效”。。。这是我的IService.cs文件中的代码C# &引用;修改器public对此项无效";关于接口方法,c#,interface,C#,Interface,好的,因此我在从Interface(显示数据的windows窗体)调用GetClassAverage()方法时遇到问题。我也得到了下面的错误 “公共修饰符对此项无效”。。。这是我的IService.cs文件中的代码 [ServiceContract] public interface IClassRollService { [OperationContract] List<Student> GetStudentList(int semester); [Oper
[ServiceContract]
public interface IClassRollService
{
[OperationContract]
List<Student> GetStudentList(int semester);
[OperationContract]
double GetClassAverage(int anything);
}
在我的windows窗体上,我通过调用client.GetStudentList()来填充gridview,但它不适用于GetClassAverage()
我做错了什么?我错过了什么
[EDIT]已经删除了public,但我仍然无法从Windows窗体调用该方法。是否有其他方法可以将该方法返回的值转换到windows窗体中。这与我所知道的web服务有关。在接口中,所有方法都是定义为公共的。这就是为什么它告诉你“public”是无效的。只要从界面的方法定义中删除“public”关键字,一切都会好起来。您编辑的IService.cs看起来不错。您需要更改Service.cs中的实现签名以匹配您的接口:
public double GetClassAverage()
到
我去掉了public关键字,但仍然无法使用GetClassAverage()将数据绑定到标签中@关于您的编辑:
GetClassAverage()
实现没有实现接口的GetClassAverage(int)
方法,因为签名不匹配。见Steve Wong的答案。
public double GetClassAverage()
public double GetClassAverage(int anything)