c# – “接口方法”中的“修饰符public对此项无效”
发布时间:2020-12-15 19:51:15 所属栏目:百科 来源:网络整理
导读:好的,所以我在从interfacce调用方法GetClassAverage()时遇到问题(显示数据的窗体).我也得到以下错误 “修饰符public对此项无效”…这是我的IService.cs文件中的代码 [ServiceContract]public interface IClassRollService{ [OperationContract] ListStudent
好的,所以我在从interfacce调用方法GetClassAverage()时遇到问题(显示数据的窗体).我也得到以下错误
“修饰符public对此项无效”…这是我的IService.cs文件中的代码 [ServiceContract] public interface IClassRollService { [OperationContract] List<Student> GetStudentList(int semester); [OperationContract] double GetClassAverage(int anything); } 在我的Service.cs文件中 public double GetClassAverage() { double sum = 0.0; double total; foreach (Student S in Students) { sum += S.Average; } return total = sum / Students.Count(); } 在我的Windows窗体上,我通过调用client.GetStudentList()来填充gridview,但它不适用于GetClassAverage() 我做错了什么或我错过了什么? [编辑]已经公开但我仍然无法从Windows窗体调用该方法.有没有其他方法我可以从该方法获取返回值到Windows窗体.这与Web服务有关,我知道很多. 解决方法
在接口中,根据定义,所有方法都是公共的.这就是为什么它告诉你“公共”无效.只需从界面的方法定义中删除“public”关键字,一切都会好的.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |