如何在C#中将字典键值与字符串进行比较? [英] how to compare dictionary key values with string in C#?

查看:163
本文介绍了如何在C#中将字典键值与字符串进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友





我有字典



喜欢这个

Hi Friends


I have dictionary

like this

List<dictionary><string,string>> dealtower = new List<dictionary><string,string>>();





i会将一些数据添加到字典中





i will add some data into dictionary

string _dealid = range.GetCellOrNull(rowNo, 0).StringValue;
  dealtower.Add(_dealid + "♠" + _reportName, _reportdetails.ToString());





现在我想过滤已经在字典中的数据



例子

如果_dealidis有002然后它不应该再添加002它应该跳过那个id并移动到下一个



请帮助我



now i want to filter a data which is already in dictionary

example
if _dealidis having 002 then itshould not add 002 again it should skip that id and moves to next

please help me

推荐答案

这是相当奇怪的代码 - 你为什么要创建一个字典列表?如果你正在尝试做什么,为什么你的语法错误且无法编译?

如果你的意思是:

That is rather odd code - why are you trying to create a List of Dictionaries? And If that is what you are trying yo do, why is your syntax wrong and uncompilable?
If you meant:
Dictionary<string,string> dealtower = new Dictionary<string,string>();

然后尝试:

Then Try:

if (!dealtower.ContainsKey("002"))
    {
    ...
    }

如果你没有,那么你需要纠正你所说的意思的语法并向我们展示它的真实含义!

If you didn't, then you need to correct the syntax of what you did mean and show us what it really looks like!


这篇关于如何在C#中将字典键值与字符串进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆