开发者

Whitespace in C#

开发者 https://www.devze.com 2023-02-21 21:15 出处:网络
I\'m a bit of a sucker for tidy code, so I like to have everything indented and flowing, if you know what I mean.

I'm a bit of a sucker for tidy code, so I like to have everything indented and flowing, if you know what I mean.

private void myFunc()
{
    while(true)
    {
        //do this
    }
}

etc. Now, I know that in a text file, the tab character or four spaces or whatever is actually stored in there, ready for the next time I open it.

If I go 开发者_Python百科to compile this though, am I going to see any benefit in output filesize / compilation performance by not having tidy formatting and indentation, or does the compiler just ignore everything that isn't important?


One of the compilation steps is known as tokenization. This step removes all of the whitespace and comments from your code. As long as your code parses correctly, there's no difference between well formatted or poorly formatted code in terms of runtime speed.


Your source code files would be smaller if you used only the bare minimum of white space, but the compiled file would remain the same. Favour readability of your source code.


Spaces or tabs make no difference to the compiler.


No difference in the compiled output, just the source


The compiler converts your textual code into CIL, so all the formatting will be removed and it will make no difference to your dll's/exe's file size, so you can format it how ever you like.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号