먼저 목록을 설정하십시오 -
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