詳解C#中一維數(shù)組的插入
更新時間:2018年03月25日 14:11:49 作者:彬菌
本文內(nèi)容給大家分享了在C#中進(jìn)行一維數(shù)組的插入的詳細(xì)實例代碼,大家可以測試下。
一維數(shù)組的插入:
實現(xiàn)效果:在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;
}
}
}
相關(guān)文章
Unity實現(xiàn)移動物體到鼠標(biāo)點擊位置
這篇文章主要為大家詳細(xì)介紹了Unity實現(xiàn)移動物體到鼠標(biāo)點擊位置,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-08-08
Unity3D基于陀螺儀實現(xiàn)VR相機(jī)功能
這篇文章主要為大家詳細(xì)介紹了Unity3D基于陀螺儀實現(xiàn)VR相機(jī)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-04-04

