I have these TextBoxes
labeled as tb_class#
and # = 1-10
So far this is the function I have
private List<TextBox> GetCustomClasses()
{
List<TextBox> tb = new List<TextBox>();
foreach (Control con in gb_customClasses.Controls)
if (con.Name.Contains("tb_class"))
tb.Add(con as TextBox);
return tb.OrderByDescending(x => x.Name.Replace("tb_class", "")).ToList();
}
The output looks like this:
9
8
7
6
5
4
3
2
10
1
I could add a check for this, but I want it to go in perfect order. For those wondering gb_customClasses
is a groupbox
.
Solved! Final code:
private List<TextBox> GetCustomClasses()
{
List<TextBox> tb = new List<TextBox>();
foreach (Control con in gb_customClasses.Controls)
if (con.Name.Contains("tb_class"))
tb.Add(con as TextBox);
return tb.OrderByDescending(x => int.Parse(x.Name.Replace("tb_class", ""))).ToList();
}
I didn't even think about adding int.Parse