Return Class or List or Array from Method
Monkey Forums/Monkey Programming/Return Class or List or Array from Method
| ||
I want to return class from list that is inheritance from parent class, for example: Like example above, I want both children class able to share same method (I don't have to write same method, same coding in each children class) Or if Monkey Programming does not support such feature, I'm just hope that it able to return 2 parameter at once (Like an array), example: or return as reference that the value of parameter passed will be same..anything..or any suggestion to do so? Thanks in advanced. |
| ||
I don't fully understand what you mean about returning a class inherited from a parent class. But returning a class (or list, or array) is fine. For example, your array example could be done like this: And you could generate a class or list instead of an array the same way inside a function or method. You just need to understand the syntax of how they are created. You can also pass an object or array as a parameter to your function, but doing it that way you must be careful not to reallocate the passed parameter. The method above is the simplest. |
| ||
Oh cool, return array will solve my problem too, thanks. |
| ||
ThisFunction Return2Value:Int[]( a:Int, b:Int ) Local arr:Int[] = New Int[ 2 ] arr[ 0 ] = a arr[ 1 ] = b return arr EndCan be shrunk down to just three lines... Function Return2Value:Int[]( a:Int, b:Int ) Return [a, b] EndThe above version seemed a bit long-winded for something simple. |
| ||
Yeah, but I thought it was best to avoid the syntactic sugar when explaining the basic syntax. |