مرتب کردن
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[] a = new int[20];
void ADD()
{
if(textBox1.Text!="")
{
int x = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
textBox1.Focus();
counter += 1;
a[counter - 1] = x;
if (counter == 20)
{
for (int i = 0; i <= 19; i++)
listBox1.Items.Add(a[i]);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
ADD ();
}
private void button2_Click(object sender, EventArgs e)
{
Array.Sort(a);
for (int i = 0; i <= 19; i++)
listBox2.Items.Add(a[i]);
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter))
ADD ();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
نظرات شما عزیزان: