本文主要介绍了C# 数组删除元素的实现示例,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace _1207_数组删除元素 { class Program { //只能在动态数组ArrayList类中对数组执行删除元素的操作。 //因为动态数组是一个可以改变数组长度和元素个数的数据类型。 //为Program类定义一个静态方法Show public static void Show(ArrayList alist) { for ( int i = 0; i < alist.Count; i++) { Console.Write( "[{0}]:{1} " , i, alist[i]); } Console.WriteLine( "\n" ); } static void Main( string [] args) { // C#数组删除元素 ArrayList arraylist = new ArrayList(); for ( int i = 0; i < 7; i++) { arraylist.Add(i); } Console.WriteLine( "1. 数组列表的容量为{0},实际包含{1}个元素:" , arraylist.Capacity, arraylist.Count); Show(arraylist); arraylist.Remove(3); // 删除数组元素 arraylist.RemoveAt(5); // 删除指定索引位置5的元素 Console.WriteLine( "2. 数组列表的容量为{0},实际包含{1}个元素:" , arraylist.Capacity, arraylist.Count); Show(arraylist); Console.ReadLine(); } } } |
C# 数组批量删除
1
2
3
|
List< int > aa = new List< int > {1,2,3,4,5 }; List< int > bb = new List< int > { 1,2,3 }; aa.RemoveAll(p=>bb.Contains(p)); |
到此这篇关于C# 数组删除元素的实现示例的文章就介绍到这了,更多相关C# 数组删除元素内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/CQL_K21/article/details/87187752