比较后将结果添加到列表中 [英] Add results to a list after compare
本文介绍了比较后将结果添加到列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本文件,用于将其客户ID与数据库中的客户ID和状态字典进行比较。在进行比较后,我需要将每个具有客户ID的状态编译为List String,以便我可以再次使用它来检查数据库中的其他详细信息。如果有人有一个例子我可以使用吗?
我尝试过:
if(!mapping.ContainsKey(ssn))
{
newfile + = line + Environment.NewLine;
}
else
{
List< String> x = mapping.Where(w => w.Value.Contains(TX))
.Select(n => n.Value).ToList();
}
mapping是我字典的名称,但到目前为止这似乎不起作用。我需要将比较结果添加到列表中。
解决方案
成为智能开发人员并查看文档:Dictionary(TKey,TValue).ContainsKey Method(TKey)(System.Collections.Generic) [ ^ ]
这是一个基于你的评论和原始问题的例子
Dictionary< string,int> mapping =
new Dictionary< string,int>();
mapping.Add( cat, 2 跨度>);
mapping.Add( dog, 1 跨度>);
mapping.Add( llama, 0 跨度>);
mapping.Add( iguana, - 1);
List< String> x = mapping.Where(w = > w.Key.Contains( a))
。选择(n = > n.Key)。ToList();
I have a text file that compares its customer ID with a dictionary of Customer ID and State from the database. After it does the compare I need to compile every state with its Customer ID into a List String so I can use that again to check additional details in my database. If someone has an example I can use?
What I have tried:
if (!mapping.ContainsKey(ssn)) { newfile += line + Environment.NewLine; } else { List<String> x = mapping.Where(w => w.Value.Contains("TX")) .Select(n => n.Value).ToList(); }
mapping is the name of my dictionary, but so far this doesn't seem to work. I need to add the results of the compare to a list.
解决方案
Be a smart developer and check the documentation: Dictionary(TKey, TValue).ContainsKey Method (TKey) (System.Collections.Generic)[^]
Here is an example based on your comment and original question
Dictionary<string, int> mapping = new Dictionary<string, int>(); mapping.Add("cat", 2); mapping.Add("dog", 1); mapping.Add("llama", 0); mapping.Add("iguana", -1); List<String> x = mapping.Where(w=> w.Key.Contains("a")) .Select(n => n.Key).ToList();
这篇关于比较后将结果添加到列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文