Updating serial no in existing list using Linq

There could be many ways to update or change the serial number value in existing list. Using LINQ, we can update the serial number without using our normal loop. This can be done with help of Lambda Expression as below -

int rowIndexNumber = 0;

myExistingList.ToList()
              .ForEach(rowItem =>
                          {
                            rowIndexNumber +=1;
                            rowItem.RowSerialNumber = rowIndexNumber;
                           }
                       );

The above code can be shorter and written in more efficient but here it is for easy understanding.

Cheers!!!

blog comments powered by Disqus