在C#中的List集合操作过程中,有时候需要清空List集合中的元素对象,将之重置为一个初始化的List集合对象,此时就可以使用到List集合的扩展方法Clear()方法,此方法将清空List集合中所有的元素对象,清空后List集合中的元素个数为0。

例如有个List<int>的集合list1,内部存储10个数字,清空list1中的元素可使用下列语句:

List<int> list1 = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

list1.Clear();

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案