简体   繁体   English

C#中的#line processor指令增加了行号

[英]#line processor directive in C# increases the line number

The #line processor directive in C# increases the line number for each line to the end of file or until it reaches another #line processor directive; C#中的#line processor指令将每行的行号增加到文件末尾,或者直到达到另一个#line处理器指令; an auto incremental line number. 自动增量行号。

That was interesting! 那太有趣了! For example: 例如:

try
{
#line 110
    act();
    throw new InvalidOperationException();
}
catch (Exception x) { Console.WriteLine(x); }

Shows that an exception happened at line 111 (Not 110!). 显示在第111行发生异常(不是110!)。

Question: Assume that #line shows a line number different from real line number. 问题:假设#line显示的行号与实际行号不同。 For example #line 110 is actually placed at real line number 13. Now is there a way to cancel the functionality of #line and show that an exception happened on actual line 23 (not 120)? 例如,#line #line 110实际上被放置在实际的第13行。现在是否有办法取消#line的功能并显示在实际的第23行(而不是120)上发生了异常?

Note: I just want to be sure I am not missing anything (or doing anything stupid). 注意:我只是想确定我没有遗漏任何东西(或做任何愚蠢的事情)。

I am working with Visual Studio 2012 on a .NET 4.5 project. 我在.NET 4.5项目上使用Visual Studio 2012。

You're looking for #line default , which reverts back to the natural line numbering. 您正在寻找#line default ,它会恢复为自然行编号。
See the documentation 请参阅文档

#line N directive set difference between real line and virtual N line. #line N指令设置实线和虚N线之间的差异。 To restore real line counting use #line default . 要恢复实线计数,请使用#line default

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM