+ 2
A mathed with 2 returns?
in c# can you create a mathed that returns 2 integers ? it is really important for me to know
2 Respuestas
+ 6
One possible solution is to return an array.
+ 4
You have a couple of options (in order of what would be my preference):
Create a class and return that:
class MyResult { public int[] Array { get; set; } public int Integer { get; set; } } ... private MyResult FunctionName(int[] inputArray) { return new MyResult { Array = ..., Integer = ... }; }
You could use a built-in type that basically makes the definition of the custom class a bit easier:
private Tuple<int[], int> FunctionName(int[] inputArray) { return Tuple.Create( ..., ... ); }
You can use an out parameter:
private int[] FunctionName(int[] inputArray, out int integerResult) { integerResult = 123; return new int[] { ... }; }
(Obviously function names and properties, etc, are just examples... I assume you'll pick more meaningful names)
https://stackoverflow.com/questions/3130372/c-sharp-function-returning-two-values