Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0059 Divide by zero exception

Dividing by zero value generates the DivideByZeroException. using System; class Program { static void Main(string[] args) { int i = 4; int y = 0; int result = i / y; Console.WriteLine("result="+result); } } The output: C:\g>Program.exe Unhandled Exception: System.DivideByZeroException: Attempted to divide by zero. at Program.Main(String[] args)