我正在尝试遍历字符串列表并检查它们是否针对单个字符串。如果没有找到匹配,那么我们需要退出代码。如果只有1中设置字符串,但只要你有多个字符串,如果第一个不匹配明显的代码退出太早只有在没有匹配的情况下循环遍历列表和“返回”
// loadedObj.Settings contains the list of strings, can be any number of strings
foreach (var currentCheckBox in loadedObj.Settings.Where(currentCheckBox => currentCheckBox != null))
{
// docTypeAlias is a single string that needs to be matched
var docTypeAlias = sender.ContentType.Alias;
// This is the current value of currentCheckBox
var requiredTypeAlias = currentCheckBox;
if (!requiredTypeAlias.Equals(docTypeAlias)) return;
}
的代码工作正常。
'currentCheckBox'似乎是一个CheckBox。 CheckBox如何成为一个字符串列表?你的代码也会尝试任何与你的文本无关的东西。你可以编辑来澄清类型,你的实际目标是什么? – 2012-02-29 00:53:44
为什么不使用常规的'foreach'循环? – udidu 2012-02-29 00:55:51
对不起,这是从其他代码复制的名称,它实际上是从xml文件读入的checkBox项目列表。 – 2012-02-29 01:04:19