[英]Clearing a DateTime list in C#
我在foreach循環中有一個正在使用的DateTime列表,並且在每個循環的開始都需要有一個清晰的列表
我想知道是否有任何內置方法可以清除它,還是必須在foreach循環中嵌套for循環才能清除列表?
我已經嘗試了這兩種方法,但是它們都不起作用
foreach( DateTime i in listname){
listname.Remove(i);
}
listname.RemoveAll();
您可以使用clear
功能清除列表
public static void Main(string[] args)
{
//Your code goes here
List<DateTime> dtList = new List<DateTime>(){
DateTime.Now
};
Console.WriteLine("Before count " + dtList.Count());
dtList.Clear();
Console.WriteLine("After count " + dtList.Count());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.