首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

Visual C#.NET 追蹤與偵錯 (1):Debug 類別基礎、建立範例專案、WriteLine/Indent/XmlDocument 輸出

     編輯:關於C語言

Debug 類別基本概念

程式執行時透過 Debug 方法產生訊息,監控執行順序、偵錯、效能度量。預設輸出至 VS IDE「輸出」視窗。

建立 conInfo 範例專案步驟

  1. 啟動 VS.NET → 新專案 → Visual C# Console Application → 名稱 conInfo。
  2. 頂端引用 using System.Diagnostics;。
  3. 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 等進階技巧。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved