Answers for "check if list contains element c#"

3

check if list of objects contains value c#

bool contains = pricePublicList.Any(p => p.Size == 200);
Posted by: Guest on March-04-2020
0

check list exist in list c# if matches any

List<int> nums1 = new List<int> { 2, 4, 6, 8, 10 };
List<int> nums2 = new List<int> { 1, 3, 6, 9, 12};

if (nums1.Any(x => nums2.Any(y => y == x)))
{
    Console.WriteLine("There are equal elements");
}
else
{
    Console.WriteLine("No Match Found!");
}
Posted by: Guest on November-06-2021
-1

check list exist in list c# if matches any

You could use a nested Any() for this check which is available on any Enumerable:

bool hasMatch = myStrings.Any(x => parameters.Any(y => y.source == x));
Faster performing on larger collections would be to project parameters to source and then use Intersect which internally uses a HashSet<T> so instead of O(n^2) for the first approach (the equivalent of two nested loops) you can do the check in O(n) :

bool hasMatch = parameters.Select(x => x.source)
                          .Intersect(myStrings)
                          .Any();
Posted by: Guest on November-06-2021

Code answers related to "check if list contains element c#"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language