How to create divide by zero error in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 13 / int.Parse("0");

            Console.WriteLine(n);
        }
    }
}


/*
run:


Unhandled Exception: System.DivideByZeroException: Attempted to divide by zero.
   at ConsoleApplication_C_Sharp.Program.Main(String[] args) in d:\Conso
leApplication_C_Sharp\ConsoleApplication_C_Sharp\Program.cs:line 9

*/

 



answered Mar 7, 2017 by avibootz

Related questions

1 answer 208 views
1 answer 142 views
142 views asked Oct 8, 2022 by avibootz
1 answer 196 views
1 answer 90 views
90 views asked Jul 27, 2023 by avibootz
1 answer 120 views
...