在進行同行代碼審查時,我觀察到我的同事編寫了一個循環遍歷字典並具有各種開關情況的代碼,其中一種情況是他通過字典獲取其他值。請參閱以下代碼片段迭代字典對象時所通過的詞典:需要的建議
foreach (KeyValuePair<string, string> kvp in dictionary_Object)
{
switch (kvp.Key)
{
case "Name":
{
string ipconnection = GetIPConnectionName(dictionary_Object);
//Do something with ipconnection
}
break;
case "TCPIPPort":
//Do something
break;
case "TCPIPAddress":
//Do something
break;
case "DefaultProViewNXGAddress":
//Do something
break;
// Setting values of the Timeout parameters
case "Comms_TimeOut":
case "Comms_Retries":
case "FW_File_Retries":
Another_Dictionary[kvp.Key] = kvp.Value;
break;
}
}
有沒有更好的方法來即興創建。
什麼是代碼的問題?你可以從改善身份開始。 – nnunes10
此問題屬於http://codereview.stackexchange.com –
可能您需要使用http://codereview.stackexchange.com/ – Valentin