c# - Change value in List<T> using Linq -
i have list whant change value of double property in list if property has decimals.
if x.value has decimals, want change value take first decimal woithout rounding it.
i'm trying can't right: (only assignment, call, increment, decrement, await, , new object expressions can used statement)
var newlist = correctionqoutas.tolist() .foreach(x => x.value%1 != 0 ? x.value = convert.todouble(string.format("{0:0.0}", x)) : x.value = x.value);
edit: correctionqoutas custom object has 4 properties. double starttime, double endtime, double value , string id.
you can't modify collection while you're iterating it.
here's simple approach
var list=correctionqoutas.tolist(); for(int i=0; i<list.count(); i++) { if(list[i].value % 1 != 0) { list[i].value = convert.todouble(string.format("{0:0.0}", list[i].value)) ; } }
Comments
Post a Comment