本文主要介绍了C# 数组删除元素的实现示例,具体如下: using System; using System.Collections.Generic; using System.
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));
到此这篇关于C# 数组删除元素的实现示例的文章就介绍到这了,更多相关C# 数组删除元素内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: C# 数组删除元素的实现示例
本文链接: https://www.lsjlt.com/news/131838.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0