0

How to exit from the code in C#

If i write letter e in the code for example, How can I make it exit?

11th Dec 2021, 10:29 AM
Hiba Nbk
Hiba Nbk - avatar
12 odpowiedzi
+ 6
Environment.Exit(int) Parameter is the exitcode.
11th Dec 2021, 10:48 AM
Alex
Alex - avatar
+ 4
Ipang No, it's one of his cases. He is making a calculator and case '/' was adding the numbers instead of making a division. ^^
11th Dec 2021, 1:23 PM
Alex
Alex - avatar
+ 3
Could you show your code please? That will help other users to understand what you try to do!
11th Dec 2021, 10:40 AM
Lisa
Lisa - avatar
+ 2
Do you mean exiting from a loop? You could use "break" for that.
11th Dec 2021, 10:33 AM
Lisa
Lisa - avatar
+ 1
Thanks, I fixed the bug But the/ Environment.Exit(1) / is not working..
11th Dec 2021, 12:43 PM
Hiba Nbk
Hiba Nbk - avatar
0
It doesn't worked! I want to make the whole program exit... Get it?
11th Dec 2021, 10:36 AM
Hiba Nbk
Hiba Nbk - avatar
0
int n1,n2; Char r; Console.WriteLine("Enter a number"); n1=int.Parse(Console.ReadLine()); Console.WriteLine("Enter an Operation:-,+,*,/,e"); r=Char.Parse(Console.ReadLine()); Console.WriteLine("Enter a number"); n2=int.Parse(Console.ReadLine()); switch(r) { case '+': Console.WriteLine(n1 + n2); break; case '-': Console.WriteLine(n1 - n2); break; case '*': Console.WriteLine(n1 * n2); break; case '/': Console.WriteLine(n1 / n2); break; case'e': break; }
11th Dec 2021, 11:34 AM
Hiba Nbk
Hiba Nbk - avatar
0
It's working now But I don't know how to let letter e *for example* to let it exit..
11th Dec 2021, 11:35 AM
Hiba Nbk
Hiba Nbk - avatar
0
case 'e': Environment.Exit(1); break; (fyi: Case '/' has a bug ^^)
11th Dec 2021, 12:01 PM
Alex
Alex - avatar
0
Alex, What's with the '/' thing? like needed to be escaped or what?
11th Dec 2021, 1:13 PM
Ipang
0
Hii
12th Dec 2021, 6:21 PM
Volcino MC.
Volcino MC. - avatar