程式執行時透過 Debug 方法產生訊息,監控執行順序、偵錯、效能度量。預設輸出至 VS IDE「輸出」視窗。
conInfo。using System.Diagnostics;。Main 初始化變數: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);
Debug.WriteLine("The per unit cost is " + dUnitCost);
System.Xml.XmlDocument oxml = new System.Xml.XmlDocument();
Debug.WriteLine(oxml); // 輸出命名空間與類別名稱
按 Ctrl+Alt+O 開啟「輸出」視窗觀察結果。後續將介紹 Category、WriteLineIf、Assert、TraceListener 等進階技巧。