Claudia Claudia - 6 months ago 26
C# Question

How are methods with arguments invoked?

I am trying to call a method with arguments, but it doesn't work. I have this method:

public class AllMethods
//method change state and status of entity objetivovisitacao for "Propagado"
public static void changeStatus(Guid objetivoId, IOrganizationService service, int state)
SetStateRequest setStateRequest = new SetStateRequest
EntityMoniker = new EntityReference("statuscode", objetivoId),
State = new OptionSetValue(0),
Status = new OptionSetValue(911950001),


And I need to call that method, so I tried doing it this way:


But it's wrong. Can someone explain this so that I can better understand what I'm missing here?


First create variables for the parameters of the method. Then pass them in the same order as they was declared in the method.

Guid yourObjetivoId = new Guid();
IOrganizationService yourService = New YourImplementationOfOrganizationService();
int yourState = 3;

AllMethods.changeStatus(yourObjetivoId, yourService, yourState);

From MSDN: Methods (C# Programming Guide)

The method definition specifies the names and types of any parameters that are required.
When calling code calls the method, it provides concrete values called arguments for each parameter.
The arguments must be compatible with the parameter type but the argument name (if any) used in the calling code does not have to be the same as the parameter named defined in the method