本文内容给大家分享了在C#中进行一维数组的插入的详细实例代码,大家可以测试下。
一维数组的插入:
实现效果:在1 2 3 后面插入4
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Array
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[] { 1, 2, 3 };
int[] des = addArray(array, 4, 4);
foreach (int item in des)
{
Console.WriteLine(item );
}
Console.ReadLine();
}
static int[] addArray(int[] bornArray, int index, int value)
{
ArrayList list = new ArrayList(bornArray );
if (index <0)
{
index =0 ;
}
if (index >bornArray .Length -1)
{
index = bornArray.Length;
}
list.Insert(index ,value );
int[] des = new int[list.Count ];
for (int i=0;i<list.Count;i++)
{
des[i] = (int)list[i];
}
return des;
}
}
}
织梦狗教程
本文标题为:详解C#中一维数组的插入
基础教程推荐
猜你喜欢
- C++实现ETW进行进程变动监控详解 2023-05-15
- C语言 详解字符串基础 2023-03-27
- 全面了解C语言 static 关键字 2023-03-26
- C语言实现宾馆管理系统课程设计 2023-03-13
- centos 7 vscode cmake 编译c++工程 2023-09-17
- 带你深度走入C语言取整以及4种函数 2022-09-17
- [C语言]二叉搜索树 2023-09-07
- [c语言-函数]不定量参数 2023-09-08
- C语言编程C++旋转字符操作串示例详解 2022-11-20
- C++实战之二进制数据处理与封装 2023-05-29
