相关疑难解决方法(0)

Dictionary中元素的顺序

我的问题是关于枚举字典元素

// 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)

枚举的元素将以什么顺序排列?我可以强制命令按字母顺序排列吗?

.net c# ienumerable dictionary

99
推荐指数
6
解决办法
8万
查看次数

C#在两个数字之间切换?

我试图做一个智能的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)

它说,案件不能相互解决。

谢谢你的帮助!

c# switch-statement

2
推荐指数
2
解决办法
9991
查看次数

标签 统计

c# ×2

.net ×1

dictionary ×1

ienumerable ×1

switch-statement ×1