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.
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:
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
}
System.Xml.XPath.XmlSortOrder
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
}
Edit: Another has arrived since this was originally posted.
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 and ListSortDirection are two valid choices but keep in mind this:
ListSortDirection:
SortOrder:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With