I have a List such as below.
List<int> temp = new List<int> { 3, 5, 6, 8, 2, 1, 6};
I'm going to use a LINQ to remove Min and Max value in Above List.
For example, below snippet code is just example, not working.
var newValue = from pair in temp
select pair < temp.Max() && pair > temp.Min()
Hopefully, I expect the result like below ;
newValue = {3, 5, 6, 2, 6 }
I've tried Googling, but couldn't find proper example yet.
Is it workigng when I use a LINQ ? Thanks for your time.
Try this:-
var query = temp.Where(x => x != temp.Min() && x != temp.Max()).ToList();
Working Fiddle.
You should be using where
.
from pair in temp
where pair < temp.Max() && pair > temp.Min()
select pair
Your current approach will select whether the values are in range, not filter them. That's what the where
clause is for.
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