Reputation: 79
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),
};
service.Execute(setStateRequest);
}
}
And I need to call that method, so I tried doing it this way:
AllMethods.changeStatus();
But it's wrong. Can someone explain this so that I can better understand what I'm missing here?
Upvotes: 2
Views: 78
Reputation: 4077
You are doing it wrong since, you are declaring the types of the parameter here:
AllMethods.changeStatus(Guid objetivoId, IOrganizationService service, int state);
for calling this method changeStatus(...)
, you need to pass the variable for the parameters objetivoId, service, state
.
AllMethods.changeStatus(objetivoId, service, state);
See: Passing of Parameters in C#
MSDN:
In C#, arguments can be passed to parameters either by value or by reference.
Upvotes: 0
Reputation: 32455
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
Upvotes: 2
Reputation: 23732
If you declare a method like you did:
public static void changeStatus(Guid objetivoId, IOrganizationService service, int state)
you declare parameters in the parentheses. The compiler expects the necessary input when you try to call it. So you need the fitting parameters for the call of this method. It is like a key to a lock.
Guid objetivoId = // your value
IOrganizationService service = // your value
int state = // your value
then you call it like this:
AllMethods.changeStatus(objetivoId, service, state);
You don't need to declare them again in the call! it has to be done beforehand
Upvotes: 0
Reputation: 1816
you need to pass the parameters, see documentation: Pass parameters c#
in your case
AllMethods.changeStatus(objetivoId, service, state);
Upvotes: 0
Reputation: 1525
No need to state the types of the parameters when passing them through. You should call it like this:
AllMethods.changeStatus(objetivoId, service, state);
Upvotes: 1