Jump to content

Call a function: Difference between revisions

Line 333:
/* Scalar values are passed by value by default. However, arrays are passed by reference. */
/* Pointers *sort of* work like references, though. */</lang>
 
 
=={{header|C Sharp}}==
<lang c sharp>
/* a function that has no argument */
public int MyFunction();
 
/* a function with a fixed number of arguments */
FunctionWithArguments(4, 3, 2);
 
/* a function with optional arguments */
public void OptArg();
 
public static void Main()
{
OptArg(1);
OptArg(1, 2);
OptArg(1, 2, 3);
}
public void ExampleMethod(int required,
string optionalstr = "default string",
int optionalint = 10)
/* If you know the first and the last parameter */
ExampleMethod(3, optionalint: 4);
 
/* If you know all the parameter */
ExampleMethod(3, "Hello World", 4);
 
/* Variable number of arguments use array */
public static void UseVariableParameters(params int[] list)
 
/* Obtain return value from function */
public internal MyFunction();
int returnValue = MyFunction();
 
=={{header|C++}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.