gpt4 book ai didi

c# - 接口(interface)方法上的 "The modifier public is not valid for this item"

转载 作者:行者123 更新时间:2023-11-30 13:09:27 28 4
gpt4 key购买 nike

好的,所以我在从界面(显示数据的窗口窗体)调用方法 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()

我做错了什么或者我错过了什么?

[编辑] 已经删除了 public 但我仍然无法从 Windows 窗体调用该方法。有没有其他方法可以将返回值从该方法获取到 Windows 窗体。这与网络服务有关,据我所知。

最佳答案

在一个接口(interface)中,所有的方法都是公开的。这就是为什么它告诉您“公开”无效的原因。只需从接口(interface)的方法定义中删除“public”关键字,一切都会好起来的。

关于c# - 接口(interface)方法上的 "The modifier public is not valid for this item",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10154664/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com