I have a list
List < double > newlist = new List<double>{5.0,1.1,2.1,5.1,0.2,5.2,7.5}
using System.Linq how to change all values between 5<i<6 to 5.5?
I have a list
List < double > newlist = new List<double>{5.0,1.1,2.1,5.1,0.2,5.2,7.5}
using System.Linq how to change all values between 5<i<6 to 5.5?
approach with linq - that replaces the existing List<double>
with a new one
//[5.0,1.1,2.1,5.5,0.2,5.5,7.5]
newlist = newlist.Select(x => x > 5 && x < 6 ? 5.5d : x).ToList();
approach with a for loop - that one only changes the affected values
for (int i = 0; i < newlist.Count; i++)
{
if (newlist[i] > 5 && newlist[i] < 6)
{
newlist[i] = 5.5d;
}
}