c#拆分数组并在文本框中按降序显示

c#拆分数组并在文本框中按降序显示,c#,arrays,textbox,split,C#,Arrays,Textbox,Split,我希望在文本框中显示一个文本数组,在用逗号拆分后,我将一组数字传递到textbox1中,并用逗号拆分,如何按降序对数字排序。这是我到目前为止得到的方法 private void btnCalc_Click(object sender, EventArgs e) { //string A = txtInput.Text; string[] arrText = txtInput.Text.Split(','); int[] newOne

我希望在文本框中显示一个文本数组,在用逗号拆分后,我将一组数字传递到textbox1中,并用逗号拆分,如何按降序对数字排序。这是我到目前为止得到的方法

    private void btnCalc_Click(object sender, EventArgs e)
    {
        //string A = txtInput.Text;
        string[] arrText = txtInput.Text.Split(',');
        int[] newOne = new int[]{};
        foreach (string r in arrText)
        {

        }
        txtOutput.AppendText( );
    }

您应该能够这样做:

private void btnCalc_Click(object sender, EventArgs e)
{
    //string A = txtInput.Text;
    string[] arrText = txtInput.Text.Split(',');
    txtOutput.Text = string.Join(",",arrText.Select( s => int.Parse(s)).OrderByDescending( i => i))
}

请注意,如果逗号之间的某些输入文本不是数字,则此操作将放大。

您应该可以这样做:

private void btnCalc_Click(object sender, EventArgs e)
{
    //string A = txtInput.Text;
    string[] arrText = txtInput.Text.Split(',');
    txtOutput.Text = string.Join(",",arrText.Select( s => int.Parse(s)).OrderByDescending( i => i))
}
请注意,如果逗号之间的某些输入文本不是数字,则会放大。这应该可以:

var newOne = arrText.OrderByDescending(int.Parse).ToArray();

foreach (var s in newOne)
{
      txtOutput.AppendText(s);
}
这应该起作用:

var newOne = arrText.OrderByDescending(int.Parse).ToArray();

foreach (var s in newOne)
{
      txtOutput.AppendText(s);
}