ListnumbersList = new List { 10, 20, 30, 40 }; numbersList.Clear(); // clear the list // count the number of elements in the list after clearing int count = numbersList.Count; // count will be 0
ListThe `List.Clear()` method is part of the `Microsoft.VisualStudio.TestTools.UnitTesting` package library, which is provided by Microsoft's Visual Studio testing framework. This package is used for writing unit tests in C# and includes a variety of testing tools and methods to help developers ensure the quality of their code.namesList = new List { "Alice", "Bob", "Charlie", "Dave" }; namesList.Clear(); // clear the list // check if the list contains any elements after clearing bool hasElements = namesList.Any(); // hasElements will be false