实例2_7

题目描述 

创建一个C#Windows应用程序,进行数组及应用演示。


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test2_7
{
    public partial class Test2_7 : Form
    {
        public Test2_7()
        {
            InitializeComponent();
        }

        private void lblShow_Click(object sender, EventArgs e)
        {
            int[] a = { 23, 15, 27, 12, 24 };
            int[] b = new int[5];
            Array.Copy(a, b, 5);
            b[3] = 18;
            Array.Clear(a, 0, 5);
            lblShow.Text = "数组b的原始值:" + b[0]+" " + b[1]+" "  + b[2] +" " + b[3] +" " + b[4]+"\n";
            Array.Sort(b);
            lblShow.Text += "数组b排序后的值为:" + b[0] + " " + b[1] + " " + b[2] + " " + b[3] + " " + b[4]+"\n";
            Array.Reverse(b);
            lblShow.Text += "翻转数组b的值为:" + b[0] + " " + b[1] + " " + b[2] + " " + b[3] + " " + b[4] + "\n";
            int loc = Array.IndexOf(b, 18);//查找18在数组b中的索引
            lblShow.Text += "18是数组b中的第" + (loc + 1) + "个元素";
        }
    }
}

猜你喜欢

转载自blog.csdn.net/WYJ____/article/details/80038116