源代码查重(源代码长什么样)

C#编程获取二维数组的行列数,并生成随机数组

源代码查重(源代码长什么样)

程序界面

代码:

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string[,] array1;

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            Random r = new Random();
            array1 = new string[r.Next(2,10), r.Next(2, 10)];
            label1.Text = string.Format("自动随机生成了{0}行{1}列的数组",array1.GetUpperBound(0)+1, array1.GetUpperBound(1) + 1);
            displayArray();
        }
        private void displayArray()
        {
            Random r = new Random();
            for(int i=0;i< array1.GetUpperBound(0) + 1;i++)
            {
                for (int j = 0; j < array1.GetUpperBound(1) + 1; j++)
                {
                    array1[i, j] = r.Next(1,10).ToString();
                    textBox1.Text = textBox1.Text+array1[i, j]+" ";
                }
                textBox1.Text = textBox1.Text + "rn";
                
            }
        }
    }
}

结语:

会使用二维数组,会随机生成区间数据,掌握获得数组的上界值的GetUpperBound方法。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发表评论

登录后才能评论