詳解C#中一維數(shù)組的插入
更新時(shí)間:2018年03月25日 14:11:49 作者:彬菌
本文內(nèi)容給大家分享了在C#中進(jìn)行一維數(shù)組的插入的詳細(xì)實(shí)例代碼,大家可以測(cè)試下。
一維數(shù)組的插入:
實(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)文章
C#多線程學(xué)習(xí)之(六)互斥對(duì)象用法實(shí)例
這篇文章主要介紹了C#多線程學(xué)習(xí)之互斥對(duì)象用法,實(shí)例分析了C#中互斥對(duì)象的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
c#棧變化規(guī)則圖解示例(棧的生長(zhǎng)與消亡)
多數(shù)情況下我們不需要關(guān)心棧的變化,下文會(huì)給出一個(gè)具體的示例。另外,理解棧的變化對(duì)于理解作用域也有一定的好處,因?yàn)镃#的局部變量作用域是基于棧的。2013-11-11
Unity實(shí)現(xiàn)移動(dòng)物體到鼠標(biāo)點(diǎn)擊位置
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)移動(dòng)物體到鼠標(biāo)點(diǎn)擊位置,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08
Unity3D基于陀螺儀實(shí)現(xiàn)VR相機(jī)功能
這篇文章主要為大家詳細(xì)介紹了Unity3D基于陀螺儀實(shí)現(xiàn)VR相機(jī)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04

