.NET 2
string[] myStrings = GetMyStrings();
string test = "testValue";
如何验证 myStrings
是否包含 test
?
最佳答案
在 .NET 2.0 中,如果需要索引,可以执行以下操作:
int index = Array.FindIndex(
myStrings,
delegate(string s) { return s.Equals(test); }
);
如果 myStrings
不包含 test
,index
将为 -1
。
如果您只想检查是否存在:
bool exists = Array.Exists(
myStrings,
delegate(string s) { return s.Equals(test); }
);
关于c# - 字符串数组。包含?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3917589/