2013-09-16 31 views
-2

如何比较字符串数组与ListBox项目?

string[] parts = {"Product", "Things"}; 

ListBox中包含的项目,如

1,产品2项3.事情

我要匹配部分字符串列表框中的项目。 如果匹配我想在列表框中选择该项。
如何做到这一点??请帮我出去

回答

0
string[] parts = { "Product", "Things" }; 

for (int i = 0; i < parts.Length; i++) 
{ 
    if (listBox1.Items.Count > i && parts[i] == listBox1.Items[i]) 
    { 
     // match 
    } 
}