Does an Enum exist for Asc or Desc ordering?

前端 未结 5 621
后悔当初
后悔当初 2021-02-03 17:53

Is there an Enum natively in .NET for asceding or Desceding ordering?

I need to use the ordering concept in different libraries, and I want loose coupling as possible.

5条回答
  •  梦毁少年i
    2021-02-03 18:32

    There are more than 8 sorting enums in .NET. It goes to show, even at Microsoft engineers will re-invent the wheel. It's also interesting how wildly the commenting practices and code style varies.

    Here are the ones I've found:

    1. System.ComponentModel.ListSortDirection

      public enum ListSortDirection {
          /// 
          ///    Sort in ascending order.
          /// 
          Ascending,
          /// 
          ///    Sort in descending order.
          /// 
          Descending 
      }
      
    2. System.Data.SqlClient.SortOrder

      public enum SortOrder {
          Unspecified     = -1,
          Ascending       = 0,
          Descending      = 1
      }
      
    3. System.Data.Linq.SqlClient.SqlOrderType

      internal enum SqlOrderType {
          Ascending,
          Descending
      }
      
    4. 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
      }
      
    5. System.Windows.Forms.SortOrder

      /// 
      /// 
      ///    
      ///       Specifies how items in
      ///       a list are sorted.
      ///    
      /// 
      public enum SortOrder {
      
          /// 
          /// 
          ///    
          ///       The items are
          ///       not sorted.
          ///    
          /// 
          None = 0,
      
          /// 
          /// 
          ///    
          ///       The items
          ///       are sorted in ascending order.
          ///    
          /// 
          Ascending = 1,
      
          /// 
          /// 
          ///    
          ///       The items are
          ///       sorted in descending order.
          ///    
          /// 
          Descending = 2,
      
      }
      
    6. System.Web.Helpers.SortDirection

      public enum SortDirection {
          Ascending,
          Descending
      }
      
    7. System.Web.UI.WebControls.SortDirection

      public enum SortDirection {
      
      
          Ascending = 0,
      
      
          Descending = 1
      
      }
      
    8. System.Xml.XPath.XmlSortOrder

      public enum XmlSortOrder {
          Ascending       = 1,
          Descending      = 2,
      }
      
    9. System.Data.Common.EntitySql.AST.OrderKind

      /// 
      /// Represents order kind (none=asc,asc,desc).
      /// 
      internal enum OrderKind
      {
          None,
          Asc,
          Desc
      }
      

    Edit: Another has arrived since this was originally posted.

    1. System.Web.UI.DataVisualization.Charting

      /// 
      /// Sorting order (Ascending or Descending).
      /// 
      public enum PointSortOrder
      {
          /// 
          /// Ascending sorting order
          /// 
          Ascending, 
      
          /// 
          /// Descending sorting order
          /// 
          Descending
      }
      

提交回复
热议问题