c#中.clear()作用_清单 .Clear()方法以及C#中的示例
生活随笔
收集整理的這篇文章主要介紹了
c#中.clear()作用_清单 .Clear()方法以及C#中的示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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.
參數:不接受任何內容。
Return value: It returns nothing – it's returns type is void
返回值:不返回任何內容–返回的類型為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()作用
總結
以上是生活随笔為你收集整理的c#中.clear()作用_清单 .Clear()方法以及C#中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 厉害了,自己手写一个Java热加载!
- 下一篇: 20 图|Nacos 手摸手教程