C
C#10mo ago
MorryMar

indentation

whats the difference between these 2 lines of code? and why is both okay?
No description
19 Replies
Angius
Angius10mo ago
Why wouldn't they be and what does it have to do with indentation?
MorryMar
MorryMarOP10mo ago
oh wait
MorryMar
MorryMarOP10mo ago
bc in the course im following they use indentations
No description
MorryMar
MorryMarOP10mo ago
in while and if statements
Pobiega
Pobiega10mo ago
So do you in your snippet above. The difference seems to be the "base" level of indendation
Angius
Angius10mo ago
Yeah, and so do you
Pobiega
Pobiega10mo ago
which is probably related to top level statements
Angius
Angius10mo ago
Yeah
MorryMar
MorryMarOP10mo ago
No description
MorryMar
MorryMarOP10mo ago
yea but i tried doing one without indentations and they work
Pobiega
Pobiega10mo ago
C# isnt python
Angius
Angius10mo ago
Whitespace in C# mostly doesn't matter
Pobiega
Pobiega10mo ago
indentations dont "matter" for the compiler, but it matters a lot for reading
Angius
Angius10mo ago
We have braces for that And semicolons
MorryMar
MorryMarOP10mo ago
oh i think i see it now
MODiX
MODiX10mo 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
MorryMarOP10mo ago
No description
MorryMar
MorryMarOP10mo ago
ffs but yea i understand now thanks for the clarification
The Fog 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