This is the original version of code written by my coworker that replaces every null cells with an empty string.
for (int i = 0; i < dGV_factory.Rows.Count; i++)
{
this.dGV_factory["dGV_factory_groupID", i].Value
= this.dGV_factory["dGV_factory_groupID", i].Value ?? "";
this.dGV_factory["dGV_factory_groupID", i].Value
= this.dGV_factory["dGV_factory_groupID", i].Value ?? "";
this.dGV_factory["dGV_factory_groupID", i].Value
= this.dGV_factory["dGV_factory_groupID", i].Value ?? "";
this.dGV_factory["UE", i].Value
= this.dGV_factory["UE", i].Value ?? "";
...
}
My instant reaction: Ugh.
Being a shameless fanatic of LINQ, I decided to rewrite the code using LINQ.
foreach(DataGridViewRow row in dGV_factory.Rows)
{
//Replace every null cells with an empty string
row.Cells.Cast<DataGridViewCell>().ToList().ForEach(cell => cell.Value = cell.Value ?? "");
}
However, I'm wondering if this code is less readable than the above version, even though it is definitely compact.
In my eyes, it's definitely readable as I'm comfortable with LINQ but my coworkers have not even heard of LINQ.
Is thisWhich is a better change? Or shouldShould I at leastkeep my LINQ version or unroll the LINQ to two foreach loops iterating through every cells and replacing nulls?