Reputation: 1
I have a combobox in which i can select three items and a list that contains items i want to check first of all whether the value selected from the combobox is in list and then the list item which is same as combobox one ; want to do some ops on it.
List<string>names = af.GetBlankSignatureNames();
comboBox1.SelectedItem.ToString();//combobox value taken
How to do so?
Upvotes: 0
Views: 1208
Reputation: 223207
you can do:
if(names.Any(r=> r == comboBox1.SelectedItem.ToString())
{
// match found
}
else
{
// not found
}
Or to get the item from the list try:
string str = names.FirstOrDefault(r=> r == comboBox1.SelectedItem.ToString());
if str
is null that means string not found in the names
list, if its not null then you got the string as well, (which by the way would be same as comboBox1.SelectedItem.ToString()
)
Upvotes: 1