【发布时间】:2016-08-09 05:55:05
【问题描述】:
我有两个清单:
List<string> List1 = new List<string>()
{
"xxxxxxxx_green_xxxxxxxxxxxxx",
"xxxxxxxx_yellow_xxxxxxxxxxxxx",
"xxxxxxxx_blue_xxxxxxxxxxxxx",
"xxxxxxxx_white_xxxxxxxxxxxxx",
};
List<string> List2 = new List<string>()
{
"yyyyyyyy_blue_yyyyyyyyyyyyy",
"yyyyyyyy_green_yyyyyyyyyyyyy",
"yyyyyyyy_white_yyyyyyyyyyyyy",
"yyyyyyyy_yellow_yyyyyyyyyyyyy",
};
其中x 和y 是一个随机字符。
我想创建一个字典,将具有相同颜色的值关联起来
预期输出:
Dictionary<string, string> ExpectedDictionary = new Dictionary<string, string>()
{
{"xxxxxxxx_green_xxxxxxxxxxxxx", "yyyyyyyy_green_yyyyyyyyyyyyy"},
{"xxxxxxxx_yellow_xxxxxxxxxxxxx", "yyyyyyyy_yellow_yyyyyyyyyyyyy"},
{"xxxxxxxx_blue_xxxxxxxxxxxxx", "yyyyyyyy_blue_yyyyyyyyyyyyy"},
{"xxxxxxxx_white_xxxxxxxxxxxxx", "yyyyyyyy_white_yyyyyyyyyyyyy"}
};
最好的方法是什么?用 linq 吗?还是使用正则表达式?
【问题讨论】:
-
每个列表是否只有一个不同的颜色值?例如,我的意思是现在有 2 个绿色记录?
-
是的,每个列表只有一个不同的颜色
-
您可能会发现以下答案很有帮助。