این برنامه هم که نوشتم خوبه اول لیست باکسو مرتب میکنه و بعد دومین عنصر رو نشون میده:
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 ave2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
listBox1.Items.Add(textBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
int temp;
for (int i = listBox1.Items.Count - 1; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
if (Convert.ToInt32(listBox1.Items[j]) < Convert.ToInt32(listBox1.Items[j + 1]))
{
temp = Convert.ToInt32(listBox1.Items[j]);
listBox1.Items[j] = listBox1.Items[j + 1];
listBox1.Items[j + 1] = temp;
}
}
}
label1.Text = Convert.ToString(listBox1.Items[1]);
}
}
}
لینک سورس