I have a directory of files and I want to sort in in Array List in
a customized way. How do I do that?[color=blue]
>
>
>
>
>
>[/color]
class main
{
static void Main(string[] args)
{
string[] items = Directory.GetFi les( "c:\dir", "*.*");
ArrayList al = new ArrayList( items);
TransIdComparer Class myComp = new TransIdComparer Class();
al.Sort(myComp) ;
string topFile = (string) al[0];
}
}
/// <summary>
/// For example. This IComparer is used to sort based
// on the fourth character and onwards in each filename.
/// </summary>
public class TransIdComparer Class : IComparer
{
// Calls CaseInsensitive Comparer.Compar e with the parameters
reversed.
int IComparer.Compa re( Object x, Object y )
{
string a = Path.GetFileNam e( (string) x);
string b = Path.GetFileNam e( (string) y);
return ( a.Substring(3). CompareTo(b.Sub string(3)) );
}
}
a customized way. How do I do that?[color=blue]
>
>
>
>
>
>[/color]
class main
{
static void Main(string[] args)
{
string[] items = Directory.GetFi les( "c:\dir", "*.*");
ArrayList al = new ArrayList( items);
TransIdComparer Class myComp = new TransIdComparer Class();
al.Sort(myComp) ;
string topFile = (string) al[0];
}
}
/// <summary>
/// For example. This IComparer is used to sort based
// on the fourth character and onwards in each filename.
/// </summary>
public class TransIdComparer Class : IComparer
{
// Calls CaseInsensitive Comparer.Compar e with the parameters
reversed.
int IComparer.Compa re( Object x, Object y )
{
string a = Path.GetFileNam e( (string) x);
string b = Path.GetFileNam e( (string) y);
return ( a.Substring(3). CompareTo(b.Sub string(3)) );
}
}
Comment