.NET Fiddle

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		// This overflows as expected.
		Console.WriteLine(Add(Int32.MaxValue, 5));
		// This throws a System.OverflowException
		Console.WriteLine(Divide(Int32.MinValue, -1));
	}
	
	private static int Add(int a, int b)
	{
		return unchecked(a + b);
	}
	
	private static int Divide(int n, int d)
	{
		return unchecked (n / d);
	}
}
;