Horje
check list exist in list c# if matches any Code Example
c# does value exist in list
public int GetItemFromList() {
	List<Item> list = new List<Item>(
      new Item(1),
      new Item(2),
      new Item(3)
    );

	Item testItem = new Item(1);

	// Inside FindIndex() you can specify a lambda expression where you
	// query if an item exists like a boolean test.
	int index = list.FindIndex(item => testItem.Id == item.Id);

	// in this case out testItem.Id (1) is equal to an item in the list
	if (index > -1)
	{
		// We get here with the index 0!
      	return index;
	}
}

public class Item
{
	public int Id { get; set; }
	public Item() { }
	public Item(int id)
	{
		Id = id;
	}
}
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!");
}
check list exist in list c# if matches any
var items = (from x in parameters
                join y in myStrings on x.Source equals y
                select x)
            .ToList();
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(); 




Csharp

Related
Convert C# Class to xml wth xsd.exe Code Example Convert C# Class to xml wth xsd.exe Code Example
unity create file name datetime Code Example unity create file name datetime Code Example
unity set terrain to image Code Example unity set terrain to image Code Example
admob unity Code Example admob unity Code Example
unity lerp position Code Example unity lerp position Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9