详解C#中一维数组的插入
程序员文章站
2023-12-16 11:08:52
一维数组的插入:
实现效果:在1 2 3 后面插入4
using system;
using system.collections;
using syste...
一维数组的插入:
实现效果:在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; } } }