确认它可以使用
1. 确保 Debug 是当前的解决方案配置。
2. 如果“解决方案资源管理器”窗口不可见,请按 CTRL+ALT+L 组合键以显示此窗口。
3. 右键单击“conInfo”,然后单击“属性”。
4. 在 conInfo 属性页左窗格中,在“配置”文件夹下,请确保箭头指向“调试”。
5. 在“配置”文件夹上面的“配置”下拉列表框中,单击“活动(调试)”或“调试”,然后单击“确定”。
6. 按 CTRL+ALT+O 以显示“输出”窗口。
7. 按 F5 键以运行该代码。在出现“断言失败”对话框时,单击“忽略”。
8. 在“控制台”窗口中,按 ENTER 键。此时程序即已完成,“输出”窗口应显示以下输出:
Debug Information-Product Starting The product name is Widget The available units on hand are100 The per unit cost is 1.03 System.Xml.XmlDocument Field: The product name is Widget Field: The units on hand are100 Field: The per unit cost is1.03 Calc: Total Cost is 103 This message WILL appear ---- DEBUG ASSERTION FAILED ---- ---- Assert Short Message ---- Message will appear since dUnitcost < 1 is false ---- Assert Long Message ---- at Class1.Main(String[] args) \class1.cs(34) The product name is Widget The available units on hand are100 The per unit cost is 1.03 Debug Information-Product Ending Trace Information-Product Starting The product name is Widget Field: The product name isWidget This message WILL appear Trace Information-Product Ending |
9. “控制台”窗口和 Output.txt 文件应显示以下输出:
The product name is Widget The available units on hand are 100 The per unit cost is 1.03 Debug Information-Product Ending Trace Information-Product Starting The product name is Widget Field: The product name is Widget This message WILL appear Trace Information-Product Ending |
注意:Output.txt 文件与 conInfo 可执行文件 (conInfo.exe) 位于同一目录中。通常情况下,该目录是存储项目源的 \bin 文件夹,默认情况下为 C:\Documents and Settings\User login\My Documents\Visual Studio Projects\conInfo\bin。
完整代码列表
using System;
using System.Diagnostics;
class Class1
{
[STAThread]
static void Main(string[] args)
{
string sProdName = "Widget";
int iUnitQty = 100;
double dUnitCost = 1.03;
Debug.WriteLine("Debug Information-Product Starting ");
Debug.Indent();
Debug.WriteLine("The product name is "+sProdName);
Debug.WriteLine("The available units on hand are"+iUnitQty.ToString());
Debug.WriteLine("The per unit cost is "+ dUnitCost.ToString());
System.Xml.XmlDocument oxml = new System.Xml.XmlDocument();
Debug.WriteLine(oxml);
Debug.WriteLine("The product name is "+sProdName,"Field");
Debug.WriteLine("The units on hand are"+iUnitQty,"Field");
Debug.WriteLine("The per unit cost is"+dUnitCost.ToString(),"Field");
Debug.WriteLine("Total Cost is "+(iUnitQty * dUnitCost),"Calc");
Debug.WriteLineIf(iUnitQty > 50, "This message WILL appear");
Debug.WriteLineIf(iUnitQty < 50, "This message will NOT appear");
Debug.Assert(dUnitCost > 1, "Message will NOT appear");
Debug.Assert(dUnitCost < 1, "Message will appear since dUnitcost < 1 is false");
TextWriterTraceListener tr1 = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(tr1);
TextWriterTraceListener tr2 = new TextWriterTraceListener(System.IO.File.CreateText("Output.txt"));
Debug.Listeners.Add(tr2);
Debug.WriteLine("The product name is "+sProdName);
Debug.WriteLine("The available units on hand are"+iUnitQty);
Debug.WriteLine("The per unit cost is "+dUnitCost);
Debug.Unindent();
Debug.WriteLine("Debug Information-Product Ending");
Debug.Flush();
Trace.WriteLine("Trace Information-Product Starting ");
Trace.Indent();
Trace.WriteLine("The product name is "+sProdName);
Trace.WriteLine("The product name is"+sProdName,"Field" );
Trace.WriteLineIf(iUnitQty > 50, "This message WILL appear");
Trace.Assert(dUnitCost > 1, "Message will NOT appear");
Trace.Unindent();
Trace.WriteLine("Trace Information-Product Ending");
Trace.Flush();
Console.ReadLine();
}
}
|
注意:要使此代码示例发挥作用,必须通过将 using System.Diagnostics; 粘贴为第一行代码来添加 System.Diagonstics 名称空间。
【相关文章】
| 共2页: 上一页 [1] 2 | ||
|
|
||||
| · 视频访谈:网管员如何踏.. · 首届中国IT工程师生态.. · 华为路由器配置 · 全面解析35岁技术人的.. · 企业数据恢复指南 · 龙芯要做中国的“奔腾” · 2008年上半年全国软考.. · 交换机故障解决指南 |
· Vista SP1对决XP SP3 · LAMP技术精解 · 微软出价446亿美元收购.. · 网络故障排除宝典 · AIX操作系统管理应用(.. · 华为员工自杀频频拷问.. · 三层交换技术专题 · ARP攻击防范与解决方案 |
|||
|
||||
| · SQL Server 2008/2005.. · SOA 面向服务架构 · SQL Server 2008/2005.. · iSCSI应用与发展 · RAID——磁盘阵列基础 · Apache技术专题 · 三层交换技术专题 · SQL Server入门到精通 |
· Apache技术专题 · 国际文档格式标准开战 · 路由器设置与口令恢复 · 打造安全服务器 · PHP开发应用手册 · SOA 面向服务架构 · 企业数据恢复指南 · ADSL应用面面俱到 |
|||
|
||||
| · iSCSI应用与发展 · SQL Server入门到精通 · SQL Server 2008/2005.. · SOA 面向服务架构 · Apache技术专题 · iSCSI应用与发展 · 三层交换技术专题 · Apache技术专题 |
· 企业数据恢复指南 · RAID——磁盘阵列基础 · 路由器设置与口令恢复 · SOA 面向服务架构 · ADSL应用面面俱到 · ADSL应用面面俱到 · 反垃圾邮件技术应用 · 访问控制列表(ACL)介绍 |
|||