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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -