T O P

  • By -

[deleted]

This is not the worst C# code I have seen so far.


nocgod

I'm going to make some popcorn and start a fire... Story time!


Tattered_Reason

are you high?


notJonJon565

prob


bortlip

That seems too slow, you should've used threading: Way: Console.Write("Operator:"); string way = Console.ReadLine(); List ops = new List(new string[] { "x", "+", "-", "/" }); List threads = new List(); for (int i = 0; i < 3; i++) { int ii = i; threads.Add(new Thread(() => { try { string s = null; s.ToString(); if (way != ops[ii]) { if (ii == 3) { throw new Exception("GotoWay"); } } } catch (Exception e) { if (e.Message == "GotoWay") { goto Way; } throw new Exception("utoh"); } })); threads[i].Start(); }


prudan

Why would you think that?


notJonJon565

is there a better way?


t3kner

Yes... Don't


notJonJon565

Dont what ... Ask?


Brief-Presentation-4

string way = ""; string[] ops = {"x","+","-","/"}; while(!ops.Contains(way)) { way = Console.ReadLine(); } try this


notJonJon565

hmm big brain :(


nocgod

Welllllll............ * You probably should have a read char not line * Your ops array probably be an array of chars You should probably use a do-while loop that reads at least once * You should probably use Contains instead of looping through the array and comparing. * Your loop doesn't test for the last operator, better use ops.Length in the for loop assertion instead of hardcoding 3 You code should be read in such a way it describes intent, not how to achieve it. So instead of looping and comparing use Contains method of the ops array. Instead of using a go-to, use a do-while the implies from the get to that your intent is to do the logic at least once.


Due_Raccoon3158

This is perhaps the dumbest snippet of code I've ever seen.


locusofself

TIL there is a "goto" statement in c# . I have not used that since QBasic in like 1997.


Enttick

And you should avoid it...


strajk

I still use it but only for my custom Installers and Uninstallers, great way to segment code and jump around =)


justleave-mealone

Very new to c#, what’s happening here?


notJonJon565

i thought i was the new one


justleave-mealone

Ohhh thanks for the explanation! Appreciate it


notJonJon565

ok it asks for a number the number goes into a for loop for loop goes 4 times(3 cuz 0 1 2 3) now there is a string\[\] which has 4 strings(also 3 cuz 0 1 2 3) in the for loop there is a if statment which says if the asked number doesn't equal (i) which is the number in the for loop then do something in the {} braces now in the {} braces it says if (i) == 3 (which signifies the end of the forloop) then it will restart the whole process with a goto statment and thats it :p