我的问题是关于枚举字典元素
// Dictionary definition
private Dictionary<string, string> _Dictionary = new Dictionary<string, string>();
// add values using add
_Dictionary.Add("orange", "1");
_Dictionary.Add("apple", "4");
_Dictionary.Add("cucumber", "6");
// add values using []
_Dictionary["banana"] = 7;
_Dictionary["pineapple"] = 7;
// Now lets see how elements are returned by IEnumerator
foreach (KeyValuePair<string, string> kvp in _Dictionary)
{
Trace.Write(String.Format("{0}={1}", kvp.Key, kvp.Value));
}
Run Code Online (Sandbox Code Playgroud)
枚举的元素将以什么顺序排列?我可以强制命令按字母顺序排列吗?
我试图做一个智能的switch语句,而不是使用20+ if语句。我试过了
private int num;
switch(num)
{
case 1-10:
Return "number is 1 through 10"
break;
default:
Return "number is not 1 through 10"
}
Run Code Online (Sandbox Code Playgroud)
它说,案件不能相互解决。
谢谢你的帮助!