我碰到下面的錯誤在我的代碼,我不知道爲什麼:場從未分配,將永遠有它的默認值0
警告 - 'SummaryForm.m_difficulty' is never assigned to, and will always have its default value 0
代碼
public partial class SummaryForm : Form
{
// Declares variables with the values pulled from the 'MainForm'
int iCorrectACount = MainForm.iCorrectACount;
int iCurrentQIndex = MainForm.iCurrentQIndex;
private Difficulty m_difficulty;
public SummaryForm()
{
InitializeComponent();
double modifier = 1.0;
if (m_difficulty == Difficulty.Easy) { modifier = 1.0; }
if (m_difficulty == Difficulty.Medium) { modifier = 1.5; }
if (m_difficulty == Difficulty.Hard) { modifier = 2; }
// Sets the labels using integer values
lblCorrectNum.Text = iCorrectACount.ToString();
lblWrongNum.Text = (iCurrentQIndex - iCorrectACount).ToString();
lblScoreTotal.Text = (iCorrectACount * modifier).ToString();
}
也許這跟爲什麼lblScoreTotal.Text
不會更改爲值*修飾符,但會在另一個表單上有關係?
我在這裏問這個問題的原因是因爲有人建議我禁用警告消息,但我不認爲這是合適的解決方案?
謝謝。
我不確定如何爲您進一步闡明。你開始在你的構造函數中檢查'm_difficulty'的內容,但是沒有任何東西*會在該字段中設置一個值。 – 2013-03-15 14:48:09