3
u/royalcrescent Nov 18 '21 edited Nov 18 '21
OP, listen to humonguslizard!! And also Holliammi. In C# you can write if statements without brackets but honestly you want to make the habit of using them anyways. The moment you want more than 1 line of code to run in the case the if statement is true, you need brackets. Edit: replaced “parentheses” with “brackets” as I got confused
2
u/rasqall Nov 18 '21 edited Nov 18 '21
I believe you have mixed up parentheses and brackets. You always need parentheses in C# when writing an if statement. But you don't always need brackets if the statement only affects one line of code.
2
u/royalcrescent Nov 18 '21
Ah, forgive me. I did mean brackets!
2
u/rasqall Nov 18 '21
No worries, always nice to see people helping others. Thanks for the award my guy!
0
u/HumongousLizard Nov 18 '21 edited Nov 18 '21
it needs to be
if Console.ReadKey() == true{
Console.WriteLine("??? ?? ????")
}
5
u/rasqall Nov 18 '21
This is not the problem. The real problem is the missing parentheses like this:
if (Console.ReadKey(true)) { // do stuff }2
u/SuperShades Nov 18 '21
I don't think "true" should be passed in as an argument.
"Cannot implicitly convert type 'SystemConsoleKeyInfo' to 'bool'" is the second error.2
u/rasqall Nov 18 '21
This is true, I knew that it won’t take a bool as an argument but I wrote it for the context of the question. This is a good point OP.
1
u/SuperShades Nov 18 '21
Wait a sec. I spoke too soon lol.
From the docs: https://docs.microsoft.com/en-us/dotnet/api/system.console.readkey?view=net-6.0 Parameters intercept Boolean Determines whether to display the pressed key in the console window. true to not display the pressed key; otherwise, false.
2

7
u/hollammi Nov 18 '21
Google the syntax of an
ifstatement for the language you're working in and copy what you see