Hello everyone. Such a thing is interesting, is it possible to get comparison signs (> <=> = <=) from string and then use them?
public class Main { List<ListItem> ls = new List<ListItem>(); private void FilterButtonClick(...) { if(Combobox1.SelectedText == "Id") { if(Combobox2.Selectedtext == ">=") { var its = ls.Where(z=>z.Id>=Convert.ToInt32(Textbox1.Text)).ToList(); for(int i = 0;i<its.Count;i++) { datagridview.Rows.Add(Its[i].Name); } else if(Combobox2.Selectedtext == "<=") { var its = ls.Where(z=>z.Id<=Convert.ToInt32(Textbox1.Text)).ToList(); for(int i = 0;i<its.Count;i++) { datagridview.Rows.Add(Its[i].Name); } } } else if(Combobox1.SelectedText == "Age") { if(Combobox2.Selectedtext == ">=") { var its = ls.Where(z=>z.Age>=Convert.ToInt32(Textbox1.Text)).ToList(); for(int i = 0;i<its.Count;i++) { datagridview.Rows.Add(Its[i].Name); } else if(Combobox2.Selectedtext == "<=") { var its = ls.Where(z=>z.Age<=Convert.ToInt32(Textbox1.Text)).ToList(); for(int i = 0;i<its.Count;i++) { datagridview.Rows.Add(Its[i].Name); } } } } } public class ListItem { string Name; int Id; int Age; int birthday_date; int Height; int Weight; } I know the code was better to do with the Switch. But I wrote on the site and it was more convenient.
switch? - VladD