method invoke java return value code example

Example 1: java pass array as method parameter

/*
In java, you can create an array like this:
	new int[]{1, 2, 3};
replace `int` with whatever you want
*/

public static void doSomething(int[] list) {
	System.out.println("Something is done."); 
}

public static void main(String[] args) {
  	doSomething(new int[]{1, 2, 3});
}

Example 2: c# delegate return value invoke

public void TestIndividualInvokesRetVal( )
{
    MultiInvoke MI1 = new MultiInvoke(TestInvoke.Method1);
    MultiInvoke MI2 = new MultiInvoke(TestInvoke.Method2);
    MultiInvoke MI3 = new MultiInvoke(TestInvoke.Method3);

    MultiInvoke All = MI1 + MI2 + MI3;

    int retVal = -1;

    Console.WriteLine("Invoke individually (Obtain each return value):");
    foreach (MultiInvoke individualMI in All.GetInvocationList( ))
    {
        retVal = individualMI( );
        Console.WriteLine("\tOutput: " + retVal);
    }
}

Tags:

Java Example