一维数组的插入:
实现效果:在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; } } }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)