当前位置: 移动技术网 > IT编程>开发语言>c# > 详解C#中一维数组的插入

详解C#中一维数组的插入

2019年07月18日  | 移动技术网IT编程  | 我要评论

一维数组的插入:

实现效果:在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;
    }
  }
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网