串array.Contains? [英] string array.Contains?
本文介绍了串array.Contains?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
.NET 2
string[] myStrings = GetMyStrings();
string test = "testValue";
我如何可以验证 myStrings
包含或不测试
?
推荐答案
在.NET 2.0中,你可以做下面的,如果你想索引:
In .NET 2.0, you could do the following if you want the index:
int index = Array.FindIndex(
myStrings,
delegate(string s) { return s.Equals(test); }
);
首页
将 1
如果 myStrings
做不包含测试
。
如果您只是想检查是否存在:
If you merely want to check for existence:
bool exists = Array.Exists(
myStrings,
delegate(string s) { return s.Equals(test); }
);
这篇关于串array.Contains?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文