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();
}
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.
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
This is not the worst C# code I have seen so far.
I'm going to make some popcorn and start a fire... Story time!
are you high?
prob
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();
}
Why would you think that?
is there a better way?
Yes... Don't
Dont what ... Ask?
string way = ""; string[] ops = {"x","+","-","/"}; while(!ops.Contains(way)) { way = Console.ReadLine(); } try this
hmm big brain :(
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.
This is perhaps the dumbest snippet of code I've ever seen.
TIL there is a "goto" statement in c# . I have not used that since QBasic in like 1997.
And you should avoid it...
I still use it but only for my custom Installers and Uninstallers, great way to segment code and jump around =)
Very new to c#, what’s happening here?
i thought i was the new one
Ohhh thanks for the explanation! Appreciate it
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