C
C#12mo ago
MorryMar

indentation

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

Did you find this page helpful?