如何判断一个string字符串是否在string[]中?

 

string[] str = {"abc","def","ghi","jkl"};
if (((IList)str).Contains("abc"))
{
     MessageBox.Show("true");
}

另外,从.NET Framework的Library中可以看到,Array有实作IList接口,所以想使用IList.Contains()方法来判断。需要使用命名空间: using System.Collections;。 

 

参考:http://www.cnblogs.com/insus/archive/2011/12/16/2290093.html

 

posted on 2015-05-09 15:53  忙碌ing  阅读(883)  评论(0)    收藏  举报

导航