How to sort Custom class which is of type array as per one of its value
-
Hi, I am having a custom class which is of type array. one of its elements is date. I want all elements of this class to be be sorted on basis of date. e.g Class Payment { date; amount; order; } Another calss { Payment[] pay=new Payment[4]; for(int i=0;i<3;i++) { pay[i]=new Payment(); pay[i].date="Monday"; pay[i].amount=5; pay[i].order=abc; } //sort pay as per date that is populated in pay say pay[0].date=Monday; pay[1].date=Wednesday; pay[2].date=Tuesday; I want the entire row of pay to be sorted on basis of date. } Thanks, Mini
Best Regards, Mini Thomas
-
Hi, I am having a custom class which is of type array. one of its elements is date. I want all elements of this class to be be sorted on basis of date. e.g Class Payment { date; amount; order; } Another calss { Payment[] pay=new Payment[4]; for(int i=0;i<3;i++) { pay[i]=new Payment(); pay[i].date="Monday"; pay[i].amount=5; pay[i].order=abc; } //sort pay as per date that is populated in pay say pay[0].date=Monday; pay[1].date=Wednesday; pay[2].date=Tuesday; I want the entire row of pay to be sorted on basis of date. } Thanks, Mini
Best Regards, Mini Thomas
-
Hi, I am having a custom class which is of type array. one of its elements is date. I want all elements of this class to be be sorted on basis of date. e.g Class Payment { date; amount; order; } Another calss { Payment[] pay=new Payment[4]; for(int i=0;i<3;i++) { pay[i]=new Payment(); pay[i].date="Monday"; pay[i].amount=5; pay[i].order=abc; } //sort pay as per date that is populated in pay say pay[0].date=Monday; pay[1].date=Wednesday; pay[2].date=Tuesday; I want the entire row of pay to be sorted on basis of date. } Thanks, Mini
Best Regards, Mini Thomas
-
Mirko1980 wrote:
Populate a list with the array content.
Why? don't you like
public static void Sort(Array array, IComparer comparer)
? :doh:Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
-
Mirko1980 wrote:
Populate a list with the array content.
Why? don't you like
public static void Sort(Array array, IComparer comparer)
? :doh:Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
-
Hi Guys, I have alerady tried with IComparable but it doesn't return sorted array, maybe I am implementing in the wrong way. Can you guys help me out with the exact implementation? This payment Array is being accessed in another class say PaymentHistory and I wanna sort as per date the Payment array in PaymentHistory class.
Best Regards, Mini Thomas
-
Hi Guys, I have alerady tried with IComparable but it doesn't return sorted array, maybe I am implementing in the wrong way. Can you guys help me out with the exact implementation? This payment Array is being accessed in another class say PaymentHistory and I wanna sort as per date the Payment array in PaymentHistory class.
Best Regards, Mini Thomas
What have you tried? IComparable alone does not sort anything. Are you using Array.Sort? Or a List? Post the code you are using.