日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

c#中.clear()作用_清单 .Clear()方法以及C#中的示例

發(fā)布時間:2025/3/11 C# 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c#中.clear()作用_清单 .Clear()方法以及C#中的示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

c#中.clear()作用

C#List <T> .Clear()方法 (C# List<T>.Clear() Method)

List<T>.Clear() method is used to clear the list, it remove all elements from the list.

List <T> .Clear()方法用于清除列表,它從列表中刪除所有元素。

Syntax:

句法:

void List<T>.Clear();

Parameter: It accepts nothing.

參數(shù):不接受任何內(nèi)容。

Return value: It returns nothing – it's returns type is void

返回值:不返回任何內(nèi)容–返回的類型為void

Example:

例:

int list declaration:List<int> a = new List<int>();adding elements:a.Add(10);a.Add(20);a.Add(30);a.Add(40);a.Add(50);removing elements:a.Clear();Output:None

使用List <T> .Clear()方法從列表中刪除所有項目的C#示例 (C# Example to remove all items from the list using List<T>.Clear() Method)

using System; using System.Text; using System.Collections.Generic;namespace Test {class Program{static void printList(List<int> lst){//printing elementsforeach (int item in lst){Console.Write(item + " ");}Console.WriteLine();}static void Main(string[] args){//integer listList<int> a = new List<int>();//adding elementsa.Add(10);a.Add(20);a.Add(30);a.Add(40);a.Add(50);if (a.Count > 0){//print the listConsole.WriteLine("list elements...");printList(a);}else{Console.WriteLine("list is empty");}//clear all elementsa.Clear();//list after removing the elementsif (a.Count > 0){Console.WriteLine("list elements after removing elements...");printList(a);}else{Console.WriteLine("list is empty");}//hit ENTER to exitConsole.ReadLine();}} }

Output

輸出量

list elements... 10 20 30 40 50 list is empty

翻譯自: https://www.includehelp.com/dot-net/list-t-clear-method-with-example-in-c-sharp.aspx

c#中.clear()作用

總結(jié)

以上是生活随笔為你收集整理的c#中.clear()作用_清单 .Clear()方法以及C#中的示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。