So I am getting some files like this:
int pathLength = path.Length + 1;
var files = Directory.GetFiles ( path, "*.*", SearchOption.AllDirectories )
.Where ( s => s.EndsWith ( ".bmp", StringComparison.OrdinalIgnoreCase ) ||
s.EndsWith ( ".jpg", StringComparison.OrdinalIgnoreCase ) )
.Select ( s => s.Substring ( pathLength, s.Length - pathLength ) )
.ToList ( );
and was before sorting like this:
FileComparer fileComparer = new FileComparer ( );
files.Sort ( fileComparer );
But for Sort I need to use ToList. I am wondering if I can just add the Sort to the Linq the same way and get rid of ToList?
You’re looking for the
OrderBymethod:You can replace your
FileComparerclass withSince
false < true, this will sort strings that start with\\before other ones.