日期:2014-05-19  浏览次数:20918 次

请教Hashtable排序问题!
我用C#写了一个福彩双色球程序,关键代码如下:
public   void   CreatRandomNum()
{
Hashtable   hashtable   =   new   Hashtable();
Random   random   =   new   Random();
int   numCount   =   6;
for   (int   i   =   0;hashtable.Count <numCount;i++)
{
int   nValue=random.Next(34);
if(!hashtable.ContainsValue(nValue)&&nValue!=0)
{
hashtable.Add(nValue,nValue);
this.txtRedBall.Text+=nValue.ToString()+ "       ";
}
}
this.txtBlueBall.Text=random.Next(16)+1+ " ";
}

private   void   btnOpen_Click(object   sender,   System.EventArgs   e)
{
this.txtRedBall.Text= " ";
this.txtBlueBall.Text= " ";
CreatRandomNum();
}

private   void   btnClear_Click(object   sender,   System.EventArgs   e)
{
this.txtRedBall.Text= " ";
this.txtBlueBall.Text= " ";
}

private   void   btnExit_Click(object   sender,   System.EventArgs   e)
{
Application.Exit();
}
现在想对显示在txtRedBall中的数字从小到大排序,不会搞了,请各位帮一下忙,谢谢!

------解决方案--------------------
List <Int16> list = new List <short> ();
Random random = new Random();
int numCount = 6;
for (int i = 0; list.Count < numCount; i++)
{
int nValue = random.Next(34);
if (!list.Contains(nValue)&& nValue != 0)
{
list.Add(nValue);
}
}
list.Sort();
string text = string.Empty;
foreach (Int16 x in list)
{
text += x.ToString();
}
this.txtRedBall.Text = text;