C
Craig
I'm trying to translate the CompareFileInfoEntries class from this page:
http://aspnet.4guysfromrolla.com/articles/060403-1.2.aspx
I have to just be missing punctuation or something dumb somewhere, but it
won't work for me. Here's what I have:
public enum CompareByOptions {FileName, LastWriteTime, Length};
public class CompareFileInfoEntries : IComparer
{
private CompareByOptions compareBy = CompareByOptions.FileName;
public void New(ref CompareByOptions cBy)
{
compareBy = cBy;
}
public virtual int Compare(object file1, object file2)
{
//Convert file1 and file2 to FileInfo entries
FileInfo f1 = (FileInfo) file1;
FileInfo f2 = (FileInfo) file2;
//Compare the file names
switch(compareBy)
{
case CompareByOptions.FileName:
return(String.Compare(f1.Name, f2.Name));
case CompareByOptions.LastWriteTime:
return(DateTime.Compare(f1.LastWriteTime, f2.LastWriteTime));
case CompareByOptions.Length:
int lengthDif = Convert.ToInt32(f1.Length - f2.Length);
return(lengthDif);
default:
return(0);
}
}
}
When I try to call it like this:
CompareByOptions compareMethod = CompareByOptions.FileName;
Array.Sort(files,0,files.Length, new CompareFileInfoEntries(compareMethod));
I get this error:
gallery.aspx.cs(190): No overload for method 'CompareFileInfoEntries' takes
'1' arguments
What am I missing? Can someone please help? Thanks in advance...
Craig
http://aspnet.4guysfromrolla.com/articles/060403-1.2.aspx
I have to just be missing punctuation or something dumb somewhere, but it
won't work for me. Here's what I have:
public enum CompareByOptions {FileName, LastWriteTime, Length};
public class CompareFileInfoEntries : IComparer
{
private CompareByOptions compareBy = CompareByOptions.FileName;
public void New(ref CompareByOptions cBy)
{
compareBy = cBy;
}
public virtual int Compare(object file1, object file2)
{
//Convert file1 and file2 to FileInfo entries
FileInfo f1 = (FileInfo) file1;
FileInfo f2 = (FileInfo) file2;
//Compare the file names
switch(compareBy)
{
case CompareByOptions.FileName:
return(String.Compare(f1.Name, f2.Name));
case CompareByOptions.LastWriteTime:
return(DateTime.Compare(f1.LastWriteTime, f2.LastWriteTime));
case CompareByOptions.Length:
int lengthDif = Convert.ToInt32(f1.Length - f2.Length);
return(lengthDif);
default:
return(0);
}
}
}
When I try to call it like this:
CompareByOptions compareMethod = CompareByOptions.FileName;
Array.Sort(files,0,files.Length, new CompareFileInfoEntries(compareMethod));
I get this error:
gallery.aspx.cs(190): No overload for method 'CompareFileInfoEntries' takes
'1' arguments
What am I missing? Can someone please help? Thanks in advance...
Craig