2014-01-10 39 views

回答

0
void YourFunc(Int32[] input1, Int32[] input2, out Int32[] output1, out Int32[] output2) 
{ 
    output1 = new Int32[] { 1, 2, 3 }; 
    output2 = new Int32[] { 4, 5, 6 }; 
} 

… 

YourFunc(i1, i2, out o1, out o2); 
0

您可以將2個數組作爲參數傳遞給一個函數,但函數可以返回一個單一的東西。所以你可以用你需要返回的兩個數組創建一個對象,然後返回該對象。

1

一個方法只能有一個返回值;但是,您可以使用out參數來返回多個結果。

void MyFunction(int[] input1, int[] input2, out int[] output1, out int[] output2) 
1

使用元組:

public Tuple<Object[], Object[]> FunctionName(Object[] array1, Object[] array2) 
{ 
    //Your code 

    return new Tuple<Object[],Object[]>({},{}); 
} 
0

你肯定可以,老兄!

public ArrayGroup MyFunction(myType[] firstArg, myType[] secondArg) { 
    ArrayGroup result = new ArrayGroup(); 
    /*Do things which fill result.ArrayOne and result.ArrayTwo */ 
    return ArrayGroup; 
} 

class ArrayGroup { 
    myType[] ArrayOne { get; set;} 
    myType[] ArrayTwo { get; set;} 
} 

用你希望數組的任何類型填充myType!像stringint或複雜類型!

0

當然,你可以,開始爲響應容器:

public class Response 
{ 
    public string[] One{get;set;} 
    public string[] Two{get;set;} 
} 

而且你的方法可能看上去像

public Response DoSomething(string[] inputOne, string[] inputTwo) 
{ 
     // do some thing interesting 

     return new Respponse 
     { 
      One = new string[]{"Hello","World"}, 
      Two = new string[]{"Goodbye","Cruel","World"}, 
     } 
} 
0

方案一:創建型保持的結果:

SomeResult MyFunction(T[] arr1, T[] arr2) 
{ 
    // .. 
    return new SomeResult(r1, r2); 
} 

class SomeResult 
{ 
    public SomeResult(T[] a, T[] b) { /* .. */ } 

    // Rest of implementation... 
} 

選項二:Ret甕一個元組:

Tuple<T[], T[]> MyFunction(T[] arr1, T[] arr2) { } 

選項三:使用了參數(不這樣做):

void MyFunction(T1[] arr1, T[] arr2, out T[] result1, out T[] result2) { } 

我寧願選擇一個,並建議不要使用out參數。如果兩個參數是相同類型但不可互換我建議還爲參數創建一個類型,使其成爲具有單一結果的單個參數函數。

0

是的,你可以做到這一點!

您需要傳遞兩個輸出數組作爲該函數的參考。

這裏是代碼示例。

功能

private bool ArrayImp(string[] pArray1, string[] pArray2, ref string[] oArray1, ref string oArray2) 
{ 
    //Do your work here 
    //Here oArray1 and oArray2 are passed by reference so you can directly fill them 
    // and get back as a output. 
} 

函數調用

string[] iArray1 = null; 
string[] iArray2 = null; 
string[] oArray1 = null; 
string[] oArray2 = null; 

ArrayImp(iArray1, iArray2, oArray1, oArray2); 

在這裏,你需要通過iArray1和iArray2作爲輸入數組,你會得到oArray1和oArray2作爲輸出。

Cheeerss !!快樂編碼!

相關問題