title: Sorting a List<FileInfo> by creation date C#
body: <p>Using this example off MSDN:</p>
  
  <pre><code>using System.Collections.Generic;  
  using System.IO;  
  
  namespace CollectionTest  
  {  
      public class ListSort  
      {  
          static void Main(string[] args)  
          {  
              List&lt;FileInfo&gt; files = new List&lt;FileInfo&gt;();  
              files.Add(new FileInfo("d(1)"));  
              files.Add(new FileInfo("d"));              
              files.Add(new FileInfo("d(2)"));  
  
              files.Sort(new CompareFileInfoEntries());  
          }           
  
      }  
  
      public class CompareFileInfoEntries : IComparer&lt;FileInfo&gt; 
      {  
          public int Compare(FileInfo f1, FileInfo f2)  
          {  
              return (string.Compare(f1.Name, f2.Name));  
          }  
      }  
  
  }  
  </code></pre>
  
  <p>How would I compare the date of creation.</p>
  
  <p>F1 has a property "creation" date which is a FileSystemInfo.Datetime, yet when I try this:</p>
  
  <pre><code>  public class CompareFileInfoEntries : IComparer&lt;FileInfo&gt;
    {
        public int Compare(FileInfo f1, FileInfo f2)
        {
  
            return (DateTime.Compare(DateTime.Parse(f1.CreationTime), f2.CreationTime));
        }
    }  
  }
  </code></pre>
  
  <p>I get overload method matches for <code>String. compare(string,string)</code> 
  Note: Ive used two methods in the above script to attempt returning the creation time. Neither have worked - they would both be the same in my actual script.</p>
  
  <p>CLosest I can get is:</p>
  
  <pre><code>return (DateTime.Compare(DateTime.Parse(f1.CreationTime.ToString()), DateTime.Parse(f2.CreationTime.ToString() )));
  </code></pre>