Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why don't you use Linq extension <a href="http://msdn.microsoft.com/en-us/library/bb358497.aspx" rel="nofollow">Reverse()</a>? This can allow you to switch between ascending and descending without knowing the current sorting. If you want to use this, make sure you are referencing <code>System.Core</code> library and declaring a using directive with <code>System.Linq</code> on the top of your source file.</p> <p>Another way would be creating a class that inherits from List and modifying it a little bit like this:</p> <pre><code>public class LazyReversingList&lt;T&gt; : IList&lt;T&gt; { private Boolean m_SortedAscending; private List&lt;T&gt; m_InnerList; public Boolean IsReadOnly { get { return false; } } public Boolean SortedAscending { get { return m_SortedAscending; } } public Int32 Count { get { EnsureList(); return m_InnerList.Count; } } public T this[Int32 index] { get { EnsureList(); return m_InnerList[index]; } set { EnsureList(); m_InnerList[index] = value; } } private void EnsureList() { if (m_InnerList == null) m_InnerList = new List&lt;T&gt;(); } public Boolean Contains(T item) { EnsureList(); return m_InnerList.Contains(item); } public Boolean Remove(T item) { EnsureList(); return m_InnerList.Remove(item); } public IEnumerator&lt;T&gt; GetEnumerator() { EnsureList(); return m_InnerList.GetEnumerator(); } public Int32 IndexOf(T item) { EnsureList(); return m_InnerList.IndexOf(item); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { EnsureList(); return m_InnerList.GetEnumerator(); } public void Add(T item) { EnsureList(); m_InnerList.Add(item); } public void Clear() { EnsureList(); m_InnerList.Clear(); } public void CopyTo(T[] array, Int32 arrayIndex) { EnsureList(); m_InnerList.CopyTo(array, arrayIndex); } public void Insert(Int32 index, T item) { EnsureList(); m_InnerList.Insert(index, item); } public void RemoveAt(Int32 index) { EnsureList(); m_InnerList.RemoveAt(index); } public void Reverse() { if (!m_SortedAscending) { m_InnerList.Sort((x, y) =&gt; String.CompareOrdinal(x.DisplayName, y.DisplayName)); m_SortedAscending = true; } else { m_InnerList.Sort((x, y) =&gt; (String.CompareOrdinal(x.DisplayName, y.DisplayName) * -1)); m_SortedAscending = false; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload