虚位以待(AD)
虚位以待(AD)
首页 > 软件编程 > C#编程 > 详解C#中一维数组的插入

详解C#中一维数组的插入
类别:C#编程   作者:码皇   来源:互联网   点击:

本文内容给大家分享了在C 中进行一维数组的插入的详细实例代码,大家可以测试下。

一维数组的插入:

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

您可能感兴趣的文章:

  • 详解C#编程中一维数组与多维数组的使用
  • C#将HashTable中键列表或值列表复制到一维数组的方法
相关热词搜索: C 一维数组