I have this code:for (int i = 0; i < lst.Count(); i++){    lst[i].ColumnOrder = (short)i;}But I was trying to find a way to do it via LINQ or something else with better performance. I'm pretty sure that there are better ways to change the sequence of a column.  I use this code in a drag & drop context.
Change one column data from List<>
c#;.net;linq
Let's have a look at some common ways to improve collection-related code:Use LINQ. LINQ is not a good fit here, because you're modifying the collection. LINQ is good for querying, but that's not what you're doing.Use foreach instead of for. That wouldn't be a good idea here either, because you do need the index.So, this means your approach is the right one in general. But there are some smaller things I would change about your code:Use the Count property instead of the Count() extension method.Change the type of i to short to avoid the cast. (If there was more than short.MaxValue (32767) items in the collection, this would cause a somewhat confusing ArgumentOutOfRangeException instead of InvalidCastException, but I think that's not a big issue.)Use a better variable name than lst. lst doesn't tell you anything about the contents of the list and shortening variable names like this is a bad idea (especially if you save just one character). The important part is what does the variable contain (columns, or something like that), not that it's List<T>, so that's what should decide how is the variable named.With that, the code would look something like this:for (short i = 0; i < columns.Count; i++){    columns[i].ColumnOrder = i;}But I was trying to find [] something else with better performance.You're not going to find that, for loop has pretty much the best possible performance.