欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

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

时间:2021-08-17 07:33:06|栏目:.NET代码|点击:

一维数组的插入:

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

上一篇:那些年,我还在学asp.net(一) 学习笔记

栏    目:.NET代码

下一篇:Asp.net 字符串操作基类(安全,替换,分解等)

本文标题:详解C#中一维数组的插入

本文地址:http://www.codeinn.net/misctech/167505.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有