4

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);
}

In my Service.cs file I have

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

On my windows form I fill a gridview by calling client.GetStudentList() but it does not work for GetClassAverage()

What am I doing wrong or what am I missing?

[EDIT] Already took out the public but I still can't call the method from the Windows Form. Is there any other way I can get the returned value from that method into to the windows form. This has something to do with the web services, that much I know.

1
  • 2
    Regarding your edit: The GetClassAverage() implementation does not implement the interface's GetClassAverage(int) method because the signatures don't match. See Steve Wong's answer.
    – phoog
    Apr 14, 2012 at 16:29

2 Answers 2

24

In an interface, all methods are public by definition. That is why it tells you "public" is not valid. Just remove the "public" keyword from your interface's method definition and everything will be fine.

2
  • 1
    I took out the public keyword but I still cant used the GetClassAverage() to bind the data into the label. @SouthShoreAK
    – Jess
    Apr 14, 2012 at 15:45
  • Thank you! Probably the easiest fix I ever tried. Regarding my own usage; For whatever reason, the Public keyword was fine in earlier Script Tasks with C# in SSIS. I guess someone decided to make it more explicit, which is probably good. Nov 24, 2021 at 0:54
5

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

public double GetClassAverage()

to

public double GetClassAverage(int anything)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.