代码之家  ›  专栏  ›  技术社区  ›  Johannes

LINQ中的升序/降序-可以通过参数更改顺序吗?

  •  69
  • Johannes  · 技术社区  · 17 年前

    我有一个方法,它被赋予参数“bool sortAscending”。现在我想使用LINQ根据这个参数创建排序列表。然后我得到了这个:

    var ascendingQuery = from data in dataList
                          orderby data.Property ascending
                          select data;
    
    var descendingQuery = from data in dataList
                          orderby data.Property descending
                          select data;
    

    4 回复  |  直到 17 年前