在 C# 中清除列表
首先,创建一个列表 −
List<int> myList = new List<int>(); myList.Add(45); myList.Add(77);
现在,要清除以上的列表,使用了 Clear() −
myList.Clear();
以下是完整的代码 −
示例
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List<int> myList = new List<int>();
myList.Add(45);
myList.Add(77);
Console.WriteLine("Elements: "+myList.Count);
myList.Clear();
Console.WriteLine("Elements after using clear: "+myList.Count);
}
}输出
Elements: 2 Elements after using clear: 0
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP