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;
        }
    }
}

原文链接:https://www.idaobin.com/archives/950.html

让我恰个饭吧.ヘ( ̄ω ̄ヘ)

支付宝 ——————- 微信
图片加载中图片加载中



恰饭广告

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

5 × 6 =