using System; public class f1 { private const int N = 2117; [Benchmark] public static int NoCheck() { int i = 0; int x = 1; while (i < N) { int j = 0; while (j <= i) { j = j + 1; x = x + (i&j); } i = i + 1; } return x; } [Benchmark] public static int OvfCheck() { int i = 0; int x = 1; while (i < N) { int j = 0; while (j <= i) { try { j = checked(j + 1); } catch(OverflowException) { return -1; } int tmp = (i&j); try { x = checked(x + tmp); } catch(OverflowException) { return -1; } } try { i = checked(i + 1); } catch(OverflowException) { return -1; } } return x; } }