【发布时间】:2013-02-12 20:32:27
【问题描述】:
我正在尝试填充一个字典,其中唯一的主题值具有应与之匹配的各种代码值。
CODE SUBJECT
7DIM-062 Recruitment and Selection
7DIM-063 Recruitment and Selection
7DIM-064 Recruitment and Selection
7DIM-065 Recruitment and Selection
7DIM-066 Recruitment and Selection
7DIM-067 Recruitment and Selection
7DIM-068 Recruitment and Selection
所以我想要的只是将 Reqruitment 和 Selection 作为唯一键添加到字典中,然后将所有相应的代码添加到列表中。 我该怎么做呢?
Dictionary<string, List<string>> dict = new Dictionary<string,List<string>>();
这是我的查询
OleDbDataReader dbReader = cmd.ExecuteReader();
while (dbReader.Read())
{
string code = (string)dbReader["CODE"];
string subject = (string)dbReader["SUBJECT"];
//???? this is the point where I would want to add the values
dict.Add(subject, new List<string>().Add(code);
【问题讨论】:
-
考虑一个 Lookup,它本质上是一个字典,每个键都有多个值。
-
@TimSchmelter 重复键?我不确定 Lookup 中的实现细节,但它确实如您所说:对于每个不同的主题,它会返回一组代码。
标签: c# idictionary oledbdatareader