How to empty a list in C#?

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

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

7条回答
  •  忘掉有多难
    2020-12-09 01:15

    You need the Clear() function on the list, like so.

    List myList = new List();
    
    myList.Add(new object()); // Add something to the list
    
    myList.Clear() // Our list is now empty
    
        

    提交回复
    热议问题