当前位置: 首页 > news >正文

湖北平台网站建设哪里好企业电子商务网站建设的最终目的

湖北平台网站建设哪里好,企业电子商务网站建设的最终目的,网站在线支付方案,深圳今天最新通知目录 一、使用的方法 1.自定义插入方法 2.使用List.Add(T) 方法 二、实例 1.示例1#xff1a;List.Add(T) 方法 2.示例#xff1a;自定义插入方法 一、使用的方法 1.自定义插入方法 首先需要定义一个一维数组#xff0c;然后修改数组的长度(这里使用Length属性获取… 目录 一、使用的方法 1.自定义插入方法  2.使用List.Add(T) 方法 二、实例 1.示例1List.Add(T) 方法 2.示例自定义插入方法 一、使用的方法 1.自定义插入方法  首先需要定义一个一维数组然后修改数组的长度(这里使用Length属性获取数组的长度然后加1作为新数组的长度)从而在其中增加一个元素。只有增加了数组的长度以后才能在这个数组中增加新的元素。 2.使用ListT.Add(T) 方法 关于 ListT.Add(T) 定义详见本文作者写的其他文章C#用Array类的FindAll方法和ListT类的Add方法按关键词在数组中检索元素并输出-CSDN博客  https://wenchm.blog.csdn.net/article/details/136032895 首先创建一个与原始数组大小相同的动态数组例如ListT。然后将原始数组的元素复制到动态数组中直到到达要插入元素的索引位置。在动态数组中插入新元素。将原始数组中剩余的元素复制到动态数组中。最后将动态数组转换回数组并返回。 二、实例 1.示例1ListT.Add(T) 方法 // 将一个元素插入到现有数组的指定索引位置 // 并将原来位于该位置的元素向后移动namespace _095_1 {class Program{static void Main(string[] args){ArgumentNullException.ThrowIfNull(args);int[] originalArray [1, 2, 3, 4, 5];int elementToInsert 10;int indexToInsert 2;int[] newArray InsertElement(originalArray, elementToInsert, indexToInsert);Console.WriteLine(string.Join(, , newArray));}static int[] InsertElement(int[] originalArray, int elementToInsert, int indexToInsert){Listint dynamicArray new(originalArray.Length);// Copy elements from original array to dynamic array until the insertion indexfor (int i 0; i indexToInsert; i){dynamicArray.Add(originalArray[i]);}// Insert the element at the specified indexdynamicArray.Add(elementToInsert);// Copy remaining elements from original array to dynamic arrayfor (int i indexToInsert; i originalArray.Length; i){dynamicArray.Add(originalArray[i]);}// Convert dynamic array to a new array and returnreturn [.. dynamicArray];}} } //运行结果 /* 1, 2, 10, 3, 4, 5*/ 2.示例自定义插入方法 //在既有数组中的指定位置插入一个新的元素 //并遍历输出新数组 namespace _095 {public partial class Form1 : Form{private Button? button1;private Button? button2;private Label? label1;private Label? label2;private TextBox? textBox1;private TextBox? textBox2;private RichTextBox? richTextBox1;private Label? label3;private TextBox? textBox3;private int[] int_array new int[8];public Form1(){InitializeComponent();StartPosition FormStartPosition.CenterScreen;Load Form1_Load;}private void Form1_Load(object? sender, EventArgs e){// // button1// button1 new Button{Location new Point(12, 9),Name button1,Size new Size(75, 23),TabIndex 0,Text 生成数组,UseVisualStyleBackColor true};button1.Click Button1_Click;// // button2// button2 new Button{Location new Point(224, 36),Name button2,Size new Size(43, 23),TabIndex 1,Text 确定,UseVisualStyleBackColor true}; button2.Click Button2_Click;// // label1// label1 new Label{AutoSize true,Location new Point(12, 42),Name label1,Size new Size(56, 17),TabIndex 2,Text 插入索引};// // label2// label2 new Label{AutoSize true,Location new Point(12, 69),Name label2,Size new Size(56, 17),TabIndex 3,Text 新数组};// // textBox1// textBox1 new TextBox{Location new Point(93, 9),Name textBox1,Size new Size(174, 23),TabIndex 4};// // textBox2// textBox2 new TextBox{Location new Point(73, 36),Name textBox2,Size new Size(40, 23),TabIndex 5}; // // richTextBox1// richTextBox1 new RichTextBox{Location new Point(12, 90),Name richTextBox1,Size new Size(254, 44),TabIndex 6,Text };// // label3// label3 new Label{AutoSize true,Location new Point(118, 42),Name label3,Size new Size(56, 17),TabIndex 7,Text 插入元素};// // textBox3// textBox3 new TextBox{Location new Point(179, 36),Name textBox3,Size new Size(40, 23),TabIndex 8};// // Form1// AutoScaleDimensions new SizeF(7F, 17F);AutoScaleMode AutoScaleMode.Font;ClientSize new Size(279, 146);Controls.Add(textBox3);Controls.Add(label3);Controls.Add(richTextBox1);Controls.Add(textBox2);Controls.Add(textBox1);Controls.Add(label2);Controls.Add(label1);Controls.Add(button2);Controls.Add(button1);Name Form1;Text 在数组中添加一个元素;}/// summary/// 生成数组事件/// 遍历生成整形数组并遍历输出/// /summaryprivate void Button1_Click(object? sender, EventArgs e){textBox1!.Clear();for (int i 0; i int_array.GetUpperBound(0) 1; i){int_array[i] i;}for (int i 0; i int_array.GetUpperBound(0) 1; i){textBox1.Text int_array[i] ;}}/// summary/// 确定插入事件/// 在生成的数组索引4的位置插入一个元素并遍历输出/// 这个事件不仅调用AddArray方法更是在调用该方法之后改变了数组的大小/// /summaryprivate void Button2_Click(object? sender, EventArgs e){richTextBox1!.Clear();if ((textBox2!.Text ! ) (textBox3!.Text !) (textBox3!.Text.Length 1)){int_array AddArray(int_array, Convert.ToInt32(textBox2!.Text), Convert.ToInt32(textBox3!.Text));for (int i 0; i int_array.GetUpperBound(0) 1; i){richTextBox1.Text int_array[i] ;}}else{MessageBox.Show(输入信息不能为空且元素长度恒为1, 提示);}}/// summary/// 向数组中插入单个元素的方法/// /summary/// param nameArrayBorn要向其中添加元素的一维数组/param/// param nameIndex添加索引/param/// param nameValue添加值/param/// returns/returnsstatic int[] AddArray(int[] ArrayBorn, int Index, int Value){if (Index ArrayBorn.Length)Index ArrayBorn.Length - 1;int[] TemArray new int[ArrayBorn.Length 1];//声明一个新的数组for (int i 0; i TemArray.Length; i){if (Index 0){if (i (Index)) //判断遍历到的索引是否小于添加索引加1TemArray[i] ArrayBorn[i];else if (i (Index))//判断遍历到的索引是否等于添加索引加1TemArray[i] Value;elseTemArray[i] ArrayBorn[i - 1];}else{if (i 0)//数组首位置TemArray[i] Value;elseTemArray[i] ArrayBorn[i - 1];}}return TemArray;}} }
http://www.w-s-a.com/news/317550/

相关文章:

  • 网上电商游戏优化大师手机版
  • 个人微信公众号怎么做微网站吗网站域名需要续费吗
  • 有效的网站建设公丹阳做网站的
  • 哪些行业做网站的多学企业网站开发
  • 外贸seo网站制作网站备案的流程
  • 网站布局教程wordpress 侧边栏位置
  • 谁有手机网站啊介绍一下dedecms 网站重复文章
  • 博客网站快速排名微信机器人免费版wordpress
  • 孝感网站建设xgshwordpress网站基础知识
  • 百度为什么会k网站长沙做网站找哪家好
  • 揭阳商城网站建设新闻稿发布平台
  • 电商网站建设免费在线优化网站
  • 厦门网站建设咨询挣钱最快的小游戏
  • 郑州网站网络营销莱芜雪野湖别墅
  • 安装iis8 添加网站河南省建设执业资格中心网站
  • 个人网站电商怎么做广州市营销型网站建设
  • 空间站做网站什么版本wordpress 勾子
  • win7网站服务器制作软件网站浏览图片怎么做的
  • 网站制作平台公司嵌入式软件开发环境
  • 网站服务器镜像微商做网站网站
  • 十大旅游电子商务网站网上定做衣服
  • 怎样进行网站备案上海发布公众号app
  • 网站后台模板论坛网站优化招商
  • 个人网站设计作品能用VUE做网站
  • 网站建设预付阿里云域名备案查询
  • 苏州本地网站免费咨询医生的软件
  • 个人网站做废品回收福建网站开发招聘
  • wordpress网站备案学设计常用的网站
  • 网站建设的频道是什么网站用什么开发软件做
  • 电子商务网站建设与规划总结外链查询网站