سلام بر برنامه نویسان عزیز ایران زمین 😉 در این مطلب کد مرتب سازی آرایه با default comparer و comparer سفارشی و reverse آرایه مرتب شده در سی شارپ را آماده کردم. انشاالله که این کد براتون مفید باشه.
کد مرتب سازی آرایه با default comparer و comparer سفارشی و reverse آرایه مرتب شده در سی شارپ :
using System;
using System.Collections;
class myReverserClass : IComparer {
int IComparer.Compare( Object x, Object y ) {
return( (new CaseInsensitiveComparer()).Compare( y, x ) );
}
}
public class SamplesArray {
public static void Main() {
String[] myArr = { "this", "is", "a", "test", "this", "is", "another", "test", "z" };
IComparer myComparer = new myReverserClass();
PrintIndexAndValues( myArr );
Array.Sort( myArr, 1, 3 );
PrintIndexAndValues( myArr );
// Sorts a section of the Array using the reverse case-insensitive comparer.
Array.Sort( myArr, 1, 3, myComparer );
PrintIndexAndValues( myArr );
// Sorts the entire Array using the default comparer.
Array.Sort( myArr );
PrintIndexAndValues( myArr );
using System.Collections;
class myReverserClass : IComparer {
int IComparer.Compare( Object x, Object y ) {
return( (new CaseInsensitiveComparer()).Compare( y, x ) );
}
}
public class SamplesArray {
public static void Main() {
String[] myArr = { "this", "is", "a", "test", "this", "is", "another", "test", "z" };
IComparer myComparer = new myReverserClass();
PrintIndexAndValues( myArr );
Array.Sort( myArr, 1, 3 );
PrintIndexAndValues( myArr );
// Sorts a section of the Array using the reverse case-insensitive comparer.
Array.Sort( myArr, 1, 3, myComparer );
PrintIndexAndValues( myArr );
// Sorts the entire Array using the default comparer.
Array.Sort( myArr );
PrintIndexAndValues( myArr );