在.NET中是否有一个用于Asc或Desc命令的Enum? 我需要在不同库中使用排序概念,并且我想尽可能地使用松耦合。在.NET中是否存在用于Asc或Desc排序的Enum?
回答
- SortOrder在System.Data.SqlClient的
- ListSortDirection在System.ComponentModel
正确答案!有什么更好的(可能是原子,简单)库使用?我将在存储库的界面中使用它,所以SortOrder是更好的选择? – Custodio 2011-06-16 13:35:45
由@andrecarluccis判断优秀的答案'ListSortDirection'更好,如果你只想升序/降序 - 因为可用性更多的目标。 – 2011-06-16 14:17:10
我会说ListSortDirection,因为另一个绑定到SqlClient。 – BrainSlugs83 2013-09-24 21:58:11
有两个,我知道: SortDirection和SortOrder
一个快速需要注意的是,这些都在System.Web.UI.WebControls
和System.Windows.Forms
命名空间分别发现,所以有他们可能不适用的可能性对于你在做什么语义上的。
SortOrder和ListSortDirection是两个有效的选择,但要记住这一点:
- 可以在.net版本1.1至4和silverlight中找到。
- 排序顺序是强制性的:ListSortDirection只有“升序”和“降序”选项,因此用户也可以选择其中的一个。
SortOrder:只在.NET版本3.5和4为Silverlight不支持
- 可用。
- 排序顺序是可选的:您也有“未指定”选项。
与Windows.Forms.SortOrder和Data.SqlClient.SortOrder
经检查第一有趣的观点具有值:
public enum SortOrder
{
None = 0,
Ascending = 1,
Descending = 2,
}
,而第二个有价值观:
public enum SortOrder
{
Unspecified = -1,
Ascending = 0,
Descending = 1,
}
可能是一个好主意,一致,特别是如果序列化。
.NET中有超过8个排序枚举。它表明,即使在微软工程师将重新发明轮子。评论实践和代码风格各不相同也很有趣。
这里是我发现的那些:
System.ComponentModel.ListSortDirection
public enum ListSortDirection { /// <devdoc> /// <para>Sort in ascending order.</para> /// </devdoc> Ascending, /// <devdoc> /// <para>Sort in descending order.</para> /// </devdoc> Descending }
System.Data.SqlClient.SortOrder
public enum SortOrder { Unspecified = -1, Ascending = 0, Descending = 1 }
System.Data.Linq.SqlClient.SqlOrderType
internal enum SqlOrderType { Ascending, Descending }
System.DirectoryServices.SortDirection
public enum SortDirection { // // Summary: // Sort from smallest to largest. For example, A to Z. Ascending, // // Summary: // Sort from largest to smallest. For example, Z to A. Descending }
System.Windows.Forms.SortOrder
/// <include file='doc\SortOrder.uex' path='docs/doc[@for="SortOrder"]/*' /> /// <devdoc> /// <para> /// Specifies how items in /// a list are sorted. /// </para> /// </devdoc> public enum SortOrder { /// <include file='doc\SortOrder.uex' path='docs/doc[@for="SortOrder.None"]/*' /> /// <devdoc> /// <para> /// The items are /// not sorted. /// </para> /// </devdoc> None = 0, /// <include file='doc\SortOrder.uex' path='docs/doc[@for="SortOrder.Ascending"]/*' /> /// <devdoc> /// <para> /// The items /// are sorted in ascending order. /// </para> /// </devdoc> Ascending = 1, /// <include file='doc\SortOrder.uex' path='docs/doc[@for="SortOrder.Descending"]/*' /> /// <devdoc> /// <para> /// The items are /// sorted in descending order. /// </para> /// </devdoc> Descending = 2, }
System.Web.Helpers.SortDirection
public enum SortDirection { Ascending, Descending }
System.Web.UI.WebControls.SortDirection
public enum SortDirection { Ascending = 0, Descending = 1 }
-
public enum XmlSortOrder { Ascending = 1, Descending = 2, }
System.Data.Common.EntitySql.AST.OrderKind
/// <summary> /// Represents order kind (none=asc,asc,desc). /// </summary> internal enum OrderKind { None, Asc, Desc }
编辑:另一个已经到来,因为这最初发布。
System.Web.UI.DataVisualization.Charting
/// <summary> /// Sorting order (Ascending or Descending). /// </summary> public enum PointSortOrder { /// <summary> /// Ascending sorting order /// </summary> Ascending, /// <summary> /// Descending sorting order /// </summary> Descending }
还要注意,虽然'SortOrder'住在System.Data中。SqlClient命名空间,它由System.Data程序集定义。 – Dejan 2015-11-17 14:30:14
查看这些我认为DirectoryServices选项是最好的,如果你认为一个命令必须存在。如果你想了解自然顺序的概念,那么SqlClient就更好了。然而,我不知道为什么有人会打扰最终发送消息“通过不以任何特定方式订购Foo而订购Foo”......也许如果您想要未指定意味着洗牌结果,这将是合理的。 – 2016-03-14 14:42:01
再仔细看看,我刚刚意识到Active Directory服务不像文件系统目录。 SqlClient的SortOrder在.NET Core中,所以是XmlSortOrder。显然,如果你不希望在SqlClient的 – 2016-03-17 13:02:58
- 1. 在Rails中实现排序ASC或DESC
- 2. MySQL的排序DESC和ASC
- 3. 在rails中实现排序asc或desc的最佳方式
- 4. 排序由XXX按ASC或DESC排序,动态排序,mysql ...
- 5. MySQL - 按某种不是ASC或DESC的顺序排列
- 6. php&wordpress ASC/DESC使用href和排序
- 7. 是什么在ASC和DESC
- 8. 手动排序concat文本(不是ASC或DESC)
- 9. dataTable的多列排序与“ASC”和“DESC”
- 10. PHP MYSQL - 按钮排序asc/desc
- 11. 如何对通用列表Asc或Desc进行排序?
- 12. 根据其他表的值排序MySQL查询ASC或DESC
- 13. Lodash - 在对象中排序对象(desc和asc)
- 14. 搜索查询顺序由asc或desc
- 15. 使用ASC或DESC命令的主键?
- 16. 在ORDER BY CASE中使用ASC/DESC()
- 17. DataView.Sort - 不仅仅是asc/desc(需要自定义排序)
- 18. MySQL订单不使用ASC或DESC
- 19. 使用Desc/Asc排序的Order By子句声明
- 20. 如何在Rails中对多个(ASC和DESC)字段进行排序或排序全文搜索?
- 21. 我如何使用underscore.js做一个asc和desc排序?
- 22. 使用SELECT进行排序下拉asc desc连接数据库
- 23. sort asc desc php,mysql
- 24. 如何使用Fluent API在ASC/DESC排序的多列上添加索引?
- 25. PHP MySQL排序顺序ASC/DESC只显示记录
- 26. Linq to sql:按datetime desc排序,然后按数据asc的时间排序?
- 27. iPhone的sqlite desc vs asc?
- 28. .NET中是否存在排序的队列?
- 29. SQL:按列排序,然后按子串混合asc和desc
- 30. Python Sorted:按值排序字典(DESC),然后按键(ASC)
你的意思的LINQ?以及为什么你需要一个枚举(不会是一个布尔就够了 - 只有两个选项) – 2011-06-16 13:19:00
我认为他实际上是一个枚举。这听起来像他只是想要某些东西用于排序方向(即当用作参数时),如果它已经在Fx某处出现了。 – heisenberg 2011-06-16 13:20:50
@YetAnotherGeek“只有两个选项”永远不是使用布尔值的有效借口。布尔存储真假。他们对其他任何东西都不明确 - 包括性别,上升和下降等。 – BrainSlugs83 2013-09-24 21:55:13