Preserving order with LINQ

前端 未结 6 1276
名媛妹妹
名媛妹妹 2020-11-22 07:15

I use LINQ to Objects instructions on an ordered array. Which operations shouldn\'t I do to be sure the order of the array is not changed?

6条回答
  •  盖世英雄少女心
    2020-11-22 07:30

    The question here is specifically referring to LINQ-to-Objects.

    If your using LINQ-to-SQL instead there is no order there unless you impose one with something like:

    mysqlresult.OrderBy(e=>e.SomeColumn)
    

    If you do not do this with LINQ-to-SQL then the order of results can vary between subsequent queries, even of the same data, which could cause an intermittant bug.

提交回复
热议问题