I've got float array
public float[] Outputs;
Somewhere in my code, something is updating the array values and causing a NaN. This is a very infrequent error and I can't work out for the life of me what's causing it.
How can I make a change with minimal code alteration to track it down? It'd be good to make that array private and rename it, then create a property called Outputs for getting and setting that does a NaN check every time it's set. Then I can easily raise an exception when the NaN is set and retrieve a call stack, rather than discovering it further down the line when another piece of code tries to use it. Something like this - that actually compiles.
I get the error:
"Bad array declarator: To declare a managed array the rank specifier precedes
the variable's identifier. To declare a fixed size buffer field, use the fixed
keyword before the field type."
Here is my code:
public float[] _outputs;
public float Outputs[int index]
{
get
{
return _outputs[index];
}
set
{
if (float.IsNaN(value))
throw new Exception("Blar blar");
_outputs[index] = value;
}
}
EDIT: Thanks for an answers people, anyone else looking for answers may want to read this: Why C# doesn't implement indexed properties?