我有一个场景,我必须发送作为输入发送的字典作为逗号分隔字符串到存储过程.
我想知道如果我这样做会有任何可能的情况,它可能会发送字典中给定键的不正确的值.
static void Main(string[] args)
{
Dictionary<int, string> test = new Dictionary<int, string>();
test.Add(1, "1");
test.Add(3, "3");
test.Add(4, "4");
test.Add(5, "5");
test.Add(2, "2");
JoinTest(test);
}
private static void JoinTest(Dictionary<int, string> test)
{
var keys = string.Join(",", test.Keys);
var values = string.Join(",", test.Values);
}
Run Code Online (Sandbox Code Playgroud)
阅读文档.它明确指出:
Dictionary.KeyCollection中键的顺序是未指定的,但它与Values属性返回的Dictionary.ValueCollection中的关联值的顺序相同.
和
Dictionary.ValueCollection中的值的顺序是未指定的,但它与Keys属性返回的Dictionary.KeyCollection中的关联键的顺序相同.
所以是的,键和值匹配,但正如评论者指出的那样,你可能已经遇到了其他问题.
| 归档时间: |
|
| 查看次数: |
914 次 |
| 最近记录: |