New user of Grasshopper 3D here, and I am in need of some C# syntax help for coding in Grasshopper 3D. I have a script, for example, that's pasted below:
public static int arraySum(int[] myArray){
int someValue = 0;
for(int i = 0; i < myArray.Length; i++){
someValue += myArray[i];
}
return someValue;
}
The above static method sums all values of an array.
From my understanding of the scripting components of C# in Grasshopper, you cannot create static methods, as everything is a non-returning void method. You assign a variable (the output) as a psuedo-return, is that correct?
Knowing that - how do I implement my above script, for example, to a C# component?
Instead of having a "return", I simply assigned a variable, for example, A as the sum. But I ran into some issues there, for example, with some C# methods like .Length not working.
The format of a method in the C# component of Grasshopper 3D is the following:
private void RunScript(int x, ref object A){
}