【发布时间】:2014-12-17 15:50:02
【问题描述】:
假设 2 个字符串数组的长度相同且不为空,我该如何制作内容列表?
我有一个字典工作,但现在我需要能够使用重复的键,所以我求助于一个列表。
string[] files = svd.file.Split(",".ToCharArray());
string[] references = svd.references.Split(",".ToCharArray());
Dictionary<string, string> frDictionary = new Dictionary<string, string>();
frDictionary = files.Zip(rReferences, (s, i) => new { s, i })
.ToDictionary(item => item.s, item => item.i);
我可以这样做:
List<string, string> jcList = new List<string, string>();
然后对两个数组进行双循环,但我知道必须存在更快的方法。
【问题讨论】:
-
",".ToCharArray() == ',' -
如果你开始编写自己的类型(列表没有字符串,字符串重载。)你还不如创建自己的类来保存数据。
-
你不能有
List<string, string>。 -
可能是列表
>?不要认为唯一键有限制,但可能是错误的。 -
Pete如果你想使用等同于List<string, string>的东西,那么你可以使用Immutable StructC# SO Immutable Struct List<string,string>
标签: c#