How to compile just one file in c#?

前端 未结 7 1269
星月不相逢
星月不相逢 2020-12-28 15:54

In VC++ I can press CTRL+F7 to compile a single file, or right click on a source file ot compile it. Is it possible to compile a single file (or current file) in C#?

7条回答
  •  一向
    一向 (楼主)
    2020-12-28 16:23

    No it is not possible to do this in C#.

    Unlike C++ a C# file cannot be reasonably compiled on it's own to determine if it has any errors. C++ achieves this through #include statements which allows a .cpp file to understand the declaration of types available. These declarations define the structure of types the current file depends on and allows the compiler to ensure they are used according to specification.

    This process is handled implicitly in C#. The set of declarations available is simply the set of all declarations in all compiled files which are otherwise accessible. There is no way to forward declare dependencies in the manner C++ does and hence no way to ensure they are being used correctly within a single file.

提交回复
热议问题