C
C#4mo ago
MorryMar

indentation

whats the difference between these 2 lines of code? and why is both okay?
No description
19 Replies
Angius
Angius4mo ago
Why wouldn't they be and what does it have to do with indentation?
MorryMar
MorryMar4mo ago
oh wait
MorryMar
MorryMar4mo ago
bc in the course im following they use indentations
No description
MorryMar
MorryMar4mo ago
in while and if statements
Pobiega
Pobiega4mo ago
So do you in your snippet above. The difference seems to be the "base" level of indendation
Angius
Angius4mo ago
Yeah, and so do you
Pobiega
Pobiega4mo ago
which is probably related to top level statements
Angius
Angius4mo ago
Yeah
MorryMar
MorryMar4mo ago
No description
MorryMar
MorryMar4mo ago
yea but i tried doing one without indentations and they work
Pobiega
Pobiega4mo ago
C# isnt python
Angius
Angius4mo ago
Whitespace in C# mostly doesn't matter
Pobiega
Pobiega4mo ago
indentations dont "matter" for the compiler, but it matters a lot for reading
Angius
Angius4mo ago
We have braces for that And semicolons
MorryMar
MorryMar4mo ago
oh i think i see it now
MODiX
MODiX4mo ago
Angius
REPL Result: Success
var x = 8; x += 1; if (true) { Console.WriteLine($"Number is {x}"); }
var x = 8; x += 1; if (true) { Console.WriteLine($"Number is {x}"); }
Console Output
Number is 9
Number is 9
Compile: 446.697ms | Execution: 45.851ms | React with ❌ to remove this embed.
MorryMar
MorryMar4mo ago
No description
MorryMar
MorryMar4mo ago
ffs but yea i understand now thanks for the clarification
Waffles from Human Resources
You can squeeze your entire source code into 1 long line and C# won't care Its not an indent based language, and personally i like that a lot more cause python is horrible to read :SCcheese:
Want results from more Discord servers?
Add your server
More Posts