تولید عدد تصادفی در آرایه ومرتب کردن
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 _2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int counter = 0;
int[] z = new int[20];
void Inter()
{
int x = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
textBox1.Focus();
counter += 1;
z[counter - 1] = x;
if (counter == 20)
{
for (int i = 0; i <= 19; i++)
listBox1.Items.Add(z[i]);
}
}
private void button1_Click(object sender, EventArgs e)
{
Inter();
}
private void button2_Click(object sender, EventArgs e)
{
Array.Sort(z);
for (int i = 0; i <= 19; i++)
listBox2.Items.Add(z[i]);
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter))
Inter();
}
}
}
نظرات شما عزیزان: