Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Clear a list in C#
Firstly, set a list −
List<int> myList = new List<int>(); myList.Add(45); myList.Add(77);
Now, to clear the above list, use Clear() −
myList.Clear();
Here is the complete code −
Example
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);
}
}
Output
Elements: 2 Elements after using clear: 0
Advertisements
