Problem With sorting of array [modified]
-
hi, i m having a integer array which i need to sort frequently example code: int[] intarray = new intarray[5]; in between the code array.sort(intarray); now this code runs fine sometime and sometime it fails error is Failed to compare two elements in the array. pla if anyone is having any idea abt this then plz do let me know regards sindhu tiwari
its me sid
modified on Friday, January 04, 2008 3:26:44 AM
-
hi, i m having a integer array which i need to sort frequently example code: int[] intarray = new intarray[5]; in between the code array.sort(intarray); now this code runs fine sometime and sometime it fails error is Failed to compare two elements in the array. pla if anyone is having any idea abt this then plz do let me know regards sindhu tiwari
its me sid
modified on Friday, January 04, 2008 3:26:44 AM
Array.Sort() fails for vanilla integer arrays? :wtf: While it's possible, I think it's highly unlikely. Have you googled for the exact exception message? I doubt if you've given the exact message, and Google returns no results.
Cheers, Vikram.
"If a trend is truly global, then that trend ought to be visible across ANY subset of that data" - fat_boy
-
Array.Sort() fails for vanilla integer arrays? :wtf: While it's possible, I think it's highly unlikely. Have you googled for the exact exception message? I doubt if you've given the exact message, and Google returns no results.
Cheers, Vikram.
"If a trend is truly global, then that trend ought to be visible across ANY subset of that data" - fat_boy
this is the error which i got "Failed to compare two elements in the array." and searched on google too but unfortunately dint got proper result if u any way to sort or any idea then plz do let me now sindhu tiwari
its me sid
-
this is the error which i got "Failed to compare two elements in the array." and searched on google too but unfortunately dint got proper result if u any way to sort or any idea then plz do let me now sindhu tiwari
its me sid
Well, could you show us what values you've put in the array then?
Deja View - the feeling that you've seen this post before.
-
Well, could you show us what values you've put in the array then?
Deja View - the feeling that you've seen this post before.
ya sure intarray[0]=1; intarray[1]=2; intarray[2]=null; intarray[3]=3; intarray[4]=null; i hope this will help you ..thanks for response regards sindhu tiwari
its me sid
-
ya sure intarray[0]=1; intarray[1]=2; intarray[2]=null; intarray[3]=3; intarray[4]=null; i hope this will help you ..thanks for response regards sindhu tiwari
its me sid
It certainly does. You can't sort an array of ints if they have nulls in them. Convert intarray into a nullable int instead, i.e. make it
int?
. Mind you, I don't see how you could have got this code past the compiler because an ordinary int can't contain a null value so the system should have choked on it.Deja View - the feeling that you've seen this post before.
-
It certainly does. You can't sort an array of ints if they have nulls in them. Convert intarray into a nullable int instead, i.e. make it
int?
. Mind you, I don't see how you could have got this code past the compiler because an ordinary int can't contain a null value so the system should have choked on it.Deja View - the feeling that you've seen this post before.
would u plz tell me how to make it a nullable int array......... regards sindhu tiwari
its me sid
-
would u plz tell me how to make it a nullable int array......... regards sindhu tiwari
its me sid
I already did. Add the question mark (?) after the int. So you would have
int?[] intarray = new int?[5];
Deja View - the feeling that you've seen this post before.