I have a Generic List of Students. I want to filter the student name starts between "a" and "e"
with the help of LINQ.
Students = Students.Where(s => s.Name.Substring(0, 1) == "a"
&& s.Name.Substring(0, 1) == "e").ToList();
Please help me to do that.
Untested by this might work:
Students = Students.Where(s => s.Name.Substring(0, 1) >= "a"
&& s.Name.Substring(0, 1) <= "e").ToList();
Alternatively
Students = Students.Where(s => ["a", "b", "c", "d", "e"]
.contains(s.Name[0]).ToList();
Range defined by less/greater, not by just ==:
Students = Students.Where(s => s.Name.Substring(0, 1) >= "a"
&& s.Name.Substring(0, 1) <= "e").ToList();
You also may want to lowercase or compare to both cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With