How to empty a list in C#?

前端 未结 7 1042
旧时难觅i
旧时难觅i 2020-12-09 00:24

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

7条回答
  •  执笔经年
    2020-12-09 01:19

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

    List 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 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.

提交回复
热议问题