Visual Studio 調試(系列文章)

  調試是軟件開發過程當中很是重要的一個部分,它具挑戰性,可是也有必定的方法和技巧。html

  Visual Studio 調試程序有助於你觀察程序的運行時行爲並發現問題。 該調試器可用於全部 Visual Studio 編程語言及其關聯的庫。 使用調試程序時,能夠中斷程序的執行以檢查代碼、檢查和編輯變量、查看寄存器、查看從源代碼建立的指令,以及查看應用程序佔用的內存空間。編程

  本系列以 Visual Studio 2019 來演示調試的方法和技巧。但願能幫助你們掌握這些技巧。它們都很簡單,卻能幫你節約大量的時間。併發

調試方法與技巧
 
示例程序
後續的調試如下面的程序爲示例進行演示說明。
  1 using System;
  2 using System.Collections.Generic;
  3 
  4 namespace Demo002_NF45_CS50
  5 {
  6     class Program
  7     {
  8         static void Main(string[] args)
  9         {
 10             var shapes = new List<Shape>
 11             {
 12                 new Triangle(4,3),
 13                 new Rectangle(7,4),
 14                 new Circle(),
 15 
 16             };
 17 
 18             foreach (var shape in shapes)
 19             {
 20                 shape.Width = 10;
 21                 shape.Draw();
 22 
 23                 int num1 = 2, num2 = 0;
 24                 num1 = num1 / num2;
 25 
 26                 Console.WriteLine();
 27             }
 28 
 29             Console.WriteLine("Press any key to exit."); // 在調試模式下保持控制檯打開
 30             Console.ReadKey();
 31         }
 32     }
 33 
 34     #region 調試示例
 35 
 36     /// <summary>
 37     ///  繪圖類(基類)
 38     /// </summary>
 39     public class Shape
 40     {
 41         #region 屬性
 42 
 43         /// <summary>
 44         ///  X 軸座標
 45         /// </summary>
 46         public int X { get; private set; }
 47 
 48         /// <summary>
 49         ///  Y 軸座標
 50         /// </summary>
 51         public int Y { get; private set; }
 52 
 53         /// <summary>
 54         ///  圖形高度
 55         /// </summary>
 56         public int Height { get; set; }
 57 
 58         /// <summary>
 59         ///  圖形寬度
 60         /// </summary>
 61         public int Width { get; set; }
 62 
 63         #endregion
 64 
 65         // 繪製圖形(虛方法)
 66         public virtual void Draw()
 67         {
 68             Console.WriteLine("Performing base class drawing tasks");// 執行基類繪圖任務
 69         }
 70     }
 71 
 72     /// <summary>
 73     ///  圓形
 74     /// </summary>
 75     class Circle : Shape
 76     {
 77         public override void Draw()
 78         {
 79             Console.WriteLine("Drawing a circle"); // 繪製一個圓
 80             base.Draw();
 81         }
 82     }
 83 
 84     /// <summary>
 85     ///  矩形
 86     /// </summary>
 87     class Rectangle : Shape
 88     {
 89         public Rectangle()
 90         {
 91           
 92         }
 93 
 94         public Rectangle(int width, int height)
 95         {
 96             Width = width;
 97             Height = height;
 98         }
 99 
100         public override void Draw()
101         {
102             Console.WriteLine("Drawing a rectangle"); // 繪製一個矩形
103             base.Draw();
104         }
105     }
106 
107     /// <summary>
108     ///  三角形
109     /// </summary>
110     class Triangle : Shape
111     {
112         public Triangle()
113         {
114 
115         }
116 
117         public Triangle(int width, int height)
118         {
119             Width = width;
120             Height = height;
121         }
122 
123         public override void Draw()
124         {
125             Console.WriteLine("Drawing a trangle");// 繪製一個三角形
126             base.Draw();
127         }
128     }
129 
130     #endregion
131 }
View Code
相關文章
相關標籤/搜索