here is what I got so for - maybe I'm doing this all wrong.
List<string> list2 = new List<string>() { "one", "two" };
List<string> list3 = new List<string>() { "three", "two"};
foreach (var item in list3)
{
bool test = list2.Any(x => x == item);
if (test == true)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false");
}
}
In this case it loops through list3 on the first Index and says - false - three is not in list2
Then it loops through list3 again and finds "two" which is true
What I would like is to only get false if there are no true statements. I need false to do something only if there no true statements
Or else another way to compare lists and if none of the values match each other then to run new code
Also I need it to tell the difference between something like hell and hello.
Here is how I got it to work
bool state = false;
foreach (var item in list3)
{
bool test = list2.Any(x => x == item);
if (test == true)
{
state = true;
}
}
if (state == true)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false");
}