I have a class Vector3 with constructor:
public Vector3 (double x, double y, double z)
{
#if DEBUG
if (double.IsNan (x)) throw something...
#endif
X = x;
...
}
I don't wanna check for NaN in release mode. So, is it a good practice to add checking only for debug mode? I have said in XML comments constructor does not check for Nan or infinity. But I can check in debug mode for better denuging right? Is this OK? Or bad pattern?
This is what you are looking for:
System.Diagnostics.Debug.Assert(!double.IsNan(x), "Some message shown if assert fails".)
It is ignored when compiling in Release mode, so there is no impact on performance (unless you're in Debug mode of course).