質問

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).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top