Visual Studio 调试(系列文章)

时间:2023-03-10 03:37:35
Visual Studio 调试(系列文章)

  调试是软件开发过程中非常重要的一个部分,它具挑战性,但是也有一定的方法和技巧。

  Visual Studio 调试程序有助于你观察程序的运行时行为并发现问题。 该调试器可用于所有 Visual Studio 编程语言及其关联的库。 使用调试程序时,可以中断程序的执行以检查代码、检查和编辑变量、查看寄存器、查看从源代码创建的指令,以及查看应用程序占用的内存空间。

  本系列以 Visual Studio 2019 来演示调试的方法和技巧。希望能帮助大家掌握这些技巧。它们都很简单,却能帮你节约大量的时间。

Visual Studio 调试(系列文章)

调试方法与技巧
示例程序
后续的调试以下面的程序为示例进行演示说明。
 using System;
using System.Collections.Generic; namespace Demo002_NF45_CS50
{
class Program
{
static void Main(string[] args)
{
var shapes = new List<Shape>
{
new Triangle(,),
new Rectangle(,),
new Circle(), }; foreach (var shape in shapes)
{
shape.Width = ;
shape.Draw(); int num1 = , num2 = ;
num1 = num1 / num2; Console.WriteLine();
} Console.WriteLine("Press any key to exit."); // 在调试模式下保持控制台打开
Console.ReadKey();
}
} #region 调试示例 /// <summary>
/// 绘图类(基类)
/// </summary>
public class Shape
{
#region 属性 /// <summary>
/// X 轴坐标
/// </summary>
public int X { get; private set; } /// <summary>
/// Y 轴坐标
/// </summary>
public int Y { get; private set; } /// <summary>
/// 图形高度
/// </summary>
public int Height { get; set; } /// <summary>
/// 图形宽度
/// </summary>
public int Width { get; set; } #endregion // 绘制图形(虚方法)
public virtual void Draw()
{
Console.WriteLine("Performing base class drawing tasks");// 执行基类绘图任务
}
} /// <summary>
/// 圆形
/// </summary>
class Circle : Shape
{
public override void Draw()
{
Console.WriteLine("Drawing a circle"); // 绘制一个圆
base.Draw();
}
} /// <summary>
/// 矩形
/// </summary>
class Rectangle : Shape
{
public Rectangle()
{ } public Rectangle(int width, int height)
{
Width = width;
Height = height;
} public override void Draw()
{
Console.WriteLine("Drawing a rectangle"); // 绘制一个矩形
base.Draw();
}
} /// <summary>
/// 三角形
/// </summary>
class Triangle : Shape
{
public Triangle()
{ } public Triangle(int width, int height)
{
Width = width;
Height = height;
} public override void Draw()
{
Console.WriteLine("Drawing a trangle");// 绘制一个三角形
base.Draw();
}
} #endregion
}