Post by Arne VajhøjPost by LuukPost by Arne VajhøjPost by Luukint number = 1;
try
{
number = number++ / 0;
}
catch { }
Console.WriteLine("number: {0}", number);
PS: I get a compile error, because the compiler detects that it
is divide by zero.
My compiler (Visual Studio 2015) does not give that error when compiling
Hm.
C:\Work>csc e.cs
Microsoft (R) Visual C# Compiler version 4.6.1590.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework,
but only supports language versions up to C# 5, which is no longer the
latest version. For compilers that support newer versions of the C#
programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
e.cs(10,22): error CS0020: Division by constant zero
C:\Work>
C:\Work>csc e.cs
Microsoft (R) Visual C# Compiler version 4.6.1590.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework,
but only supports language versions up to C# 5, which is no longer the
latest version. For compilers that support newer versions of the C#
programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
e.cs(10,22): error CS0020: Division by constant zero
C:\Work>
C:\Work>csc e.cs
Microsoft (R) Visual C# Compiler version 12.0.31101.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.
e.cs(10,22): error CS0020: Division by constant zero
C:\Work>
C:\Work>csc e.cs
Microsoft (R) Visual C# Compiler version 1.0.0.50618
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Work>
I guess somebody changed something in 2015.
Arne
"If the value of the right operand is zero, a
System.DivideByZeroException is thrown."
from this document (about 5.0):
CSharp Language Specification.docx
https://www.microsoft.com/en-us/download/confirmation.aspx?id=7029
But something is REALLY wrong....
The example from this location:
https://msdn.microsoft.com/en-us/library/system.dividebyzeroexception(v=vs.110).aspx
//EXAMPLE
using System;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
int number1 = 3000;
int number2 = 0;
Console.WriteLine((double)number1 / number2);
}
}
}
//END EXAMPLE
produces the answer '8' when compiles with .NET Frameword 4 (or above)
and 'Infinity' with .NET Frameword 3.5 (and below) ....
This was tested with Visual Studio Community 2015
Version 14.0.25431.01 Update 3