使用变量进行字典查找
字符串类型的字典和 CheckBox 是否可以通过变量字符串解析,使得变量字符串找到与其匹配的字典条目,它将相应的复选框设置为 true?
Can a dictionary of type string and CheckBox be parsed by a variable string in such a way that should the variable string find a dictionary entry that matches it, it will set the corresponding checkbox to true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,您可以使用以下代码来实现这一点。
假设您有
myDictionary
和一个字符串stringToCheck
,其中包含您想要在字典中查找的值你可以做这样的事情
Yes, you can achieve that using following code.
Let's say you have
myDictionary<string, CheckBox>
and a stringstringToCheck
which contains that value you want to find in the dictionaryYou can do something like this
Dictionary.ContainsValue 是您要找的吗?
http://msdn.microsoft.com/en-us/library/a63811ah.aspx
Is Dictionary.ContainsValue what you are looking for?
http://msdn.microsoft.com/en-us/library/a63811ah.aspx
你好像在问:我有一本字典。我想将给定字符串的相应复选框设置为 true。这可以通过以下方式完成
It seems like you're asking: I have a Dictionary. I want to set the corresponding checkbox to true for a given string. That can be accomplished by the following
我会使用 TryGetValue 来减少对字典的访问:
I would use TryGetValue to reduce the accesses to the dictionary: