好的,所以我一直試圖解決這個問題很長一段時間。我的代碼中有一個「警告」 - 「檢測到無法訪問的代碼」。我不知道如何解決這個問題,這就是我在這裏發佈的原因。下面是代碼:檢測到無法檢測到的代碼警告
public static byte Authenticate(string UserName, string Password)
{
try
{
MySqlDataAdapter DataAdapter = new MySqlDataAdapter("SELECT * FROM `Accounts` WHERE `AccountID` = '" + UserName + "'", Connection);
DataSet DSet = new DataSet();
DataAdapter.Fill(DSet, "Account");
if (DSet != null && DSet.Tables["Account"].Rows.Count > 0)
{
DataRow DR = DSet.Tables["Account"].Rows[0];
string Pass = (string)DR["Password"];
if (Pass == Password || Pass == "")
{
if (Pass == "")
{
MySqlCommand Command = new MySqlCommand("UPDATE `Accounts` SET `Password` = '" + Password + "' WHERE `AccountID` = '" + UserName + "'", Connection);
Command.ExecuteNonQuery();
}
uint LogonCount = (uint)DR["LogonCount"];
LogonCount++;
MySqlCommand Comm = new MySqlCommand("UPDATE `Accounts` SET `LogonCount` = " + LogonCount + " WHERE `AccountID` = '" + UserName + "'", Connection);
Comm.ExecuteNonQuery();
return Convert.ToByte((uint)DR["LogonType"]);
}
else
return 0;
}
else
return 0;
}
catch (Exception Exc) { General.WriteLine(Exc.ToString()); return 0; General.ServerRestart(); }
}
我不知道如何來突出它的紅色,所以我會發布具體線路:
catch (Exception Exc) { General.WriteLine(Exc.ToString()); return 0; General.ServerRestart(); }
的警告是「常規」 .ServerRestart();
當你在你突出顯示的代碼行中點擊'return 0;'時,你自然期望執行下面的語句嗎?因爲你不應該。編譯器也沒有。埃爾戈,它被標記爲無法訪問。 – 2012-03-23 03:05:31
以上不應該是一個評論...這是答案。 :)由於你正在處理異常,並且仍然期望該方法返回一個值,所以在'General.ServerRestart();'之後移動'return 0;'而不是之前。 – 2012-03-23 03:09:34