How to empty a list in C#?

It's really easy:

myList.Clear();

If by "list" you mean a List<T>, then the Clear method is what you want:

List<string> list = ...;
...
list.Clear();

You should get into the habit of searching the MSDN documentation on these things.

Here's how to quickly search for documentation on various bits of that type:

  • List Class - provides the List<T> class itself (this is where you should've started)
  • List.Clear Method - provides documentation on the method Clear
  • List.Count Property - provides documentation on the property Count

All of these Google queries lists a bundle of links, but typically you want the first one that google gives you in each case.

Tags:

C#

.Net