I want to empty a list. How to do that?
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.
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<T>
class itself (this is where you should've started)All of these Google queries lists a bundle of links, but typically you want the first one that google gives you in each case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With