Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to empty a list in C#?

Tags:

c#

.net

I want to empty a list. How to do that?

like image 970
olive Avatar asked Mar 15 '11 11:03

olive


People also ask

What is the best way of deleting a linked list of objects in C ++?

What is the best way of deleting a linked list of objects in C++? A) head = 0; or B) Use a loop to delete every object in the linked list.


2 Answers

It's really easy:

myList.Clear(); 
like image 133
Øyvind Bråthen Avatar answered Sep 29 '22 18:09

Øyvind Bråthen


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.

like image 45
Lasse V. Karlsen Avatar answered Sep 29 '22 18:09

Lasse V. Karlsen