bool isDebugMode = false; #if DEBUG isDebugMode = true; #endif
If you want to program different behaviors between debug and release builds, you must do this as follows:
#if DEBUG int[] data = new int[] {1, 2, 3, 4}; #else int[] data = GetInputData(); #endif int sum = data[0]; for (int i= 1; i < data.Length; i++) { sum += data[i]; }
Or, if you want to perform certain checks on debug versions of functions, you can do it like this:
public int Sum(int[] data) { Debug.Assert(data.Length > 0); int sum = data[0]; for (int i= 1; i < data.Length; i++) { sum += data[i]; } return sum; }
Debug.Assert will not be included in the release build.
Davy Landman Mar 17 '09 at 14:21 2009-03-17 14:21
source share