English 中文(简体)
“......公众对于此项目无效”
原标题:"The modifier public is not valid for this item" on an Interface Method
  • 时间:2012-04-14 15:13:30
  •  标签:
  • c#
  • interface

Okay, so I am having problems calling the method GetClassAverage() from the interfacce (the windows form displaying the data). I get the following error too "The modifier public is not valid for this item"... this is the code on my IService.cs file

[ServiceContract]
public interface IClassRollService
{
    [OperationContract]
    List<Student> GetStudentList(int semester);
    [OperationContract]    
    double GetClassAverage(int anything);
}

在我的服务档案中,我

public double GetClassAverage()
{
    double sum = 0.0;
    double total;
    foreach (Student S in Students)
    {
        sum += S.Average;
    }
    return total = sum / Students.Count();
}

在我的窗口表上,我通过打电话给客户填写了电网。 GetStudentList()但并不为GetClassAverage()工作。

我做了什么错误或我失踪了什么?

[EDIT]已向公众开放,但我仍然能够从Windows表格中提一下这种方法。 是否有其他办法,我可以把这种方法的回馈价值带入窗口表格。 这与我所知道的网络服务有关。

问题回答

在接口中,所有方法都按定义公开。 因此,它告诉你“公众”是不有效的。 仅从您的界面方法定义中删除“公开”关键词,所有东西都将被罚款。

Your edited IService.cs looks good. You need 页: 1change your implementation signature in Service.cs 页: 1match your interface:

public double GetClassAverage()

页: 1

public double GetClassAverage(int anything)




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签