練習 - 使用調試程式完成挑戰活動
此訓練中的程式碼挑戰可用來強化您學到的內容,並協助您在繼續之前獲得一些信心。
變數狀態挑戰
在此挑戰中,您會提供未產生預期結果的程式代碼範例。 您必須使用 RUN AND DEBUG 檢視的 [變數] 區段,以協助您找出問題。
在 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; }程序代碼批註描述所需的功能。
在 Visual Studio Code 調試程式中執行應用程式。
檢查產生的輸出。
使用 C# 調試程式工具來隔離問題。
請考慮如何更新程序代碼以符合所需的功能。