Docs-.NET-C#-指南-语言参考-预处理器指令:#line(C# 参考) #line(C# 参考)
ylbtech-Docs-.NET-C#-指南-语言参考-预处理器指令:#line(C# 参考) |
1.返回顶部 |
1、
借助 #line
,可修改编译器的行号及(可选)用于错误和警告的文件名输出。
#line default
指令将行号恢复至默认行号,这会对上一指令重新编号的行进行计数。
复制
class MainClass { static void Main() { #line 200 "Special" int i; int j; #line default char c; float f; #line hidden // numbering not affected string s; double d; } }
编译产生以下输出:
复制
Special(200,13): warning CS0168: The variable 'i' is declared but never used Special(201,13): warning CS0168: The variable 'j' is declared but never used MainClass.cs(9,14): warning CS0168: The variable 'c' is declared but never used MainClass.cs(10,15): warning CS0168: The variable 'f' is declared but never used MainClass.cs(12,16): warning CS0168: The variable 's' is declared but never used MainClass.cs(13,16): warning CS0168: The variable 'd' is declared but never used
备注
例如,如果已从原始源代码文件中删除行,但仍希望编译器基于文件中的原始行号生成输出,可在删除行后,使用 #line
来模拟原始行号。
虽然此功能主要用于 ASP.NET,但可能更多的源生成器会利用此功能。
也就是说,如果在隐藏块中遇到错误,编译器将报告错误的当前文件名和行号。
源代码文件中可包含任意数目的 #line
指令。
示例 1
另请注意,即使在隐藏行设置断点,调试程序仍将忽略它。
复制
// preprocessor_linehidden.cs using System; class MainClass { static void Main() { Console.WriteLine("Normal line #1."); // Set break point here. #line hidden Console.WriteLine("Hidden line."); #line default Console.WriteLine("Normal line #2."); } }
请参阅
2、
2.返回顶部 |
3.返回顶部 |
4.返回顶部 |
5.返回顶部 |
1、
2、
6.返回顶部 |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |