M
M
Maria2016-03-12 14:45:17
C++ / C#
Maria, 2016-03-12 14:45:17

How to sort alphabetically?

There is a code, tell me, please, how to improve it so that you can sort the result (in the column on the right) alphabetically?
u9vXl4m.png
The code:

private void btnStat_Click(object sender, EventArgs e)
        {
            string text = tbReadText.Text;
            string temp = "";
            var groups = text.Where(char.IsLetterOrDigit).GroupBy(c => c);
            foreach (var g in groups)
               temp += "Символ: "+ g.Key +" - "+ g.Count()+ " раз"+"\r\n";
            tbStat.Text = temp;
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
atticus_finch, 2016-03-12
@missbells

var groups = text.Where(char.IsLetterOrDigit).OrderBy(x => x).GroupBy(c => c);

D
Dmitry Kovalsky, 2016-03-12
@dmitryKovalskiy

Add groups.OrderBy(d=>d.Key) to the loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question