다음을 통해 공유


Divide by Zero

What will be the out put of the following code:

try
{
double k = 19; double m = 0;
k = k / m;
Console.WriteLine(Convert.ToString(k));
Console.Read();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Different data type behave differently for divide by zero exception.

The above code does not throw devide by zero exception, but it will quitly execute and 'k' will have the value of 'infinity'. So, don't depend on a exception here. However, if 'k' and 'm' are int then you will get the divideByZero exception

Comments

  • Anonymous
    July 20, 2006
    You've been kicked (a good thing) - Trackback from DotNetKicks.com
  • Anonymous
    July 22, 2006
    The comment has been removed
  • Anonymous
    September 04, 2006
    The C# team is happy to welcome you to the new look of the C# Developer Center. This is the home page...
  • Anonymous
    September 04, 2006
    The C# team is happy to welcome you to the new look of the C# Developer Center. This is the home page...