C# 数组删除元素的实现示例
作者:ClementQL 时间:2022-03-02 08:55:04
本文主要介绍了C# 数组删除元素的实现示例,具体如下:
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# 数组批量删除
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));
来源:https://blog.csdn.net/CQL_K21/article/details/87187752
标签:C#,数组,删除,元素
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java 重载(overload)与重写(override)详解及实例
2021-06-18 15:59:45
![](https://img.aspxhome.com/file/2023/2/64752_0s.png)
JPA配置方式+逆向工程映射到Entity实体类
2023-07-28 12:09:48
![](https://img.aspxhome.com/file/2023/2/57942_0s.png)
Java多线程Callable接口实现代码示例
2021-08-06 14:29:01
C#使用Dispose模式实现手动对资源的释放
2022-09-21 16:12:14
C#实现银行家算法
2023-05-01 08:04:35
![](https://img.aspxhome.com/file/2023/8/106398_0s.jpg)
Android 中View.onDraw(Canvas canvas)的使用方法
2022-11-16 16:40:48
![](https://img.aspxhome.com/file/2023/2/100622_0s.png)
C#中IEnumerable、ICollection、IList、List之间的区别
2022-07-27 18:15:07
C#委托与冒泡排序实例
2022-05-03 13:26:21
如何基于JavaFX开发桌面程序
2023-10-30 11:06:19
JAVA IO API使用详解
2021-07-27 14:45:48
![](https://img.aspxhome.com/file/2023/1/108391_0s.jpg)
C#装箱与拆箱操作的深入讲解
2023-04-29 19:10:06
![](https://img.aspxhome.com/file/2023/2/89732_0s.png)
Java 基础语法
2021-09-21 19:26:32
springboot整合mybatis-plus基于注解实现一对一(一对多)查询功能
2021-06-16 13:08:29
带你走进Maven的大门-最全Maven配置及集成idea工具总结
2022-12-06 08:41:40
![](https://img.aspxhome.com/file/2023/0/60680_0s.png)
SpringBoot中打war包需要注意事项
2023-11-05 19:44:42
![](https://img.aspxhome.com/file/2023/6/58616_0s.png)
java字符串比较获取字符串出现次数的示例
2022-03-22 16:05:39
讲解.NET环境下绘制模糊数学中隶属函数分布图第1/5页
2022-10-04 10:21:51
Java实战项目 医院预约挂号系统
2023-09-18 06:56:44
![](https://img.aspxhome.com/file/2023/2/72632_0s.png)
c#方法重写和隐藏的学习示例
2022-12-24 14:20:12
c# 委托和事件实例学习
2023-07-04 06:25:58