练习 - 使用调试器完成挑战活动

已完成

此培训中的代码挑战用于巩固你所学的知识,并在继续学习之前帮助你提升信心。

变量状态验证

在此挑战中,你将获得一个未生成预期结果的代码示例。 你需要使用断点和“运行和调试”视图的“变量”部分来帮助找出问题。

  1. 在 Visual Studio Code 编辑器中输入以下代码示例:

    /*  
    This code instantiates a value and then calls the ChangeValue method
    to update the value. The code then prints the updated value to the console.
    */
    int x = 5;
    
    ChangeValue(x);
    
    Console.WriteLine(x);
    
    void ChangeValue(int value) 
    {
        value = 10;
    }
    
  2. 代码注释描述了所需的功能。

  3. 在 Visual Studio Code 调试器中运行应用程序。

  4. 检查生成的输出。

  5. 使用 C# 调试器工具来隔离问题。

  6. 请考虑如何更新代码以匹配所需的功能。