I am doing a simple c# scripting to take a list of integer from the input and do something with it.
I notice the output value will become a value 0 if my input is empty.
Would it be possible to keep it as empty or null from the output?
int is a value type (i.e. a Struct), it cannot be null. So whenever a null is pushed into an
int argument it assumes the default value, which is zero.
I’m afraid the only way around this is to remove the
int type hint and set it back to
object. Then check for null, and only then convert the input to an integer inside the script.
x is not set to (List Access) into your script.
You can keep x a list or list as you want. But whatever I have tried the same as you said and gives an empty list A. you can check the screenshot.
I would advise to prevent null states whenever possible. Null values almost always shift the problem to another place. The problem is not that your null item becomes a type default value (which is in indeed not a good behavior), but that there are nulls in your pipeline in first place. If you expect some component to create nulls, than filter them out or break the definition at the place of occurence. There is a replace null component in GH which helps you with that. You can replace any null with a fallback value or better you replace an null with an object of a different type, such as a string. A string will cause an type conversion exception in your script.