Is it possible to retrieve the value passed in the string.Contains method?
The usage scenario would be something like this:
foreach (string x in myList)
{
if (x.Contains("Salt") || x.Contains("Sugar") || x.Contains("Pepper"))
{
MessageBox.Show("The ingredient found in this line of myList is: " + //the ingredient found)
}
}
The objective is to AVOID having to repeat code. Right now I have to do the following to achieve the desired result:
foreach (string x in myList)
{
if (x.Contains("Salt"))
{
MessageBox.Show("The ingredient found in this line of myList is: Salt");
}
if (x.Contains("Sugar"))
{
MessageBox.Show("The ingredient found in this line of myList is: Sugar");
}
if (x.Contains("Pepper"))
{
MessageBox.Show("The ingredient found in this line of myList is: Pepper");
}
}
If it's not possible is there any alternative?
Thanks in advance!