ListmyList = new List { "apple", "banana", "orange" }; Assert.IsTrue(myList.Contains("banana"));
public class Person { public string Name { get; set; } public int Age { get; set; } } ListIn both examples, the Contains method checks if the given List contains the specified object or element. The Microsoft.VisualStudio.TestTools.UnitTesting library is included in the Microsoft.VisualStudio.TestPlatform.TestFramework NuGet package.myPeople = new List { new Person{Name = "Alice", Age = 25}, new Person{Name = "Bob", Age = 30} }; Assert.IsTrue(myPeople.Contains(new Person{Name = "Bob", Age = 30}), "The list should contain a person with name Bob and age 30");