Removes all items from the list. Count is zero, Capacity is unchanged.
Using:
1 2 3 |
list.Clear(); |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { var list = new List<int>(); list.Add(100); list.Add(200); list.Add(300); list.Add(400); list.Add(500); list.Add(600); list.Add(700); list.Clear(); Console.WriteLine(list.Count);//0 Console.ReadLine(); } } |
Output:
1 2 3 |
0 |