Click here to Skip to main content
15,886,724 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralInstall assembly in the GAC Pin
Patrick Lassalle25-Apr-03 11:32
Patrick Lassalle25-Apr-03 11:32 
GeneralRe: Install assembly in the GAC Pin
J. Dunlap25-Apr-03 18:43
J. Dunlap25-Apr-03 18:43 
GeneralRe: Install assembly in the GAC Pin
Patrick Lassalle26-Apr-03 4:19
Patrick Lassalle26-Apr-03 4:19 
GeneralAutoEventWireUp question Pin
kensai25-Apr-03 9:02
kensai25-Apr-03 9:02 
QuestionDynamic Reference Locations? Pin
eidylon25-Apr-03 4:44
eidylon25-Apr-03 4:44 
AnswerRe: Dynamic Reference Locations? Pin
Andy Davey28-Apr-03 18:46
Andy Davey28-Apr-03 18:46 
GeneralRe: Dynamic Reference Locations? Pin
Mark Smithson28-Apr-03 21:30
Mark Smithson28-Apr-03 21:30 
GeneralIComparer trouble. Pin
Martin Cook24-Apr-03 6:01
professionalMartin Cook24-Apr-03 6:01 
Sorry for the long post, but I need some help. I'm writing a class that implements IComparer, and I'm having some problems. What do you make of this:

My class looks like this:

class RandomComparer : IComparer
{
private static Random c_random;
private static RandomComparer c_instance;

public static IComparer Default
{
get {return c_instance;}
} // End Default

static RandomComparer()
{
c_random = new Random();
c_instance = new RandomComparer();
} // End RandomComparer()

int IComparer.Compare(object objA, object objB)
{

// Are the objects different?
if (Comparer.Default.Compare(objA, objB) != 0)
{

// Get two random numbers.
int numberA = c_random.Next(0, m_maxSample);
int numberB = c_random.Next(0, m_maxSample);

// Compare them and return the results.
if (numberA > numberB)
return 1;
else if (numberA < numberB)
return -1;

} // End if the objects are not the same.

return 0;

} // End Compare()

} // End class RandomCompare


I use this class to sort an array like this:

string[] someArray = new string[] {"item 0", "item 2", ... "item N"};
Array.Sort(someArray, RandomComparer.Default);


Everything works fine most of the time, but every now and then the framework throws an exception that says:

"An unhandled exception of type System.ArgumentException occured in mscorlib.dll

Additional information: IComparer (or the IComparable methods it relies upon) did not
return zero when Array.Sort called x.CompareTo(x). x: value 7 x's type: String
The IComparer: RandomComparer"


If I set Visual Studio.NET to break for all exceptions, I get a different exception, this time it says:

"A first chance exception of type 'System.IndexOutOfRangeException' occured in mscorlib.dll

Addition information: Index was outside the bounds of the array."



If I elect to continue debugging in this case, the framework then throws the first exception.

I searched the Microsoft knowledge base, and did a Google search, but I couldn't find anything.

Sheesh! This should be a five minute programming task, but I've worked on this all morning long! Frown | :(

Has anyone ever run across this? Does anyone have any ideas?
GeneralRe: IComparer trouble. Pin
Martin Cook25-Apr-03 8:57
professionalMartin Cook25-Apr-03 8:57 
GeneralRe: IComparer trouble. Pin
Daniel Turini29-Apr-03 1:16
Daniel Turini29-Apr-03 1:16 
General.NET OpenSource DataGrid Pin
tanis22-Apr-03 22:49
tanis22-Apr-03 22:49 
QuestionDiscretionary Access Control Lists (DACLs) - part of the .NET framework? Pin
Duncan Edwards Jones22-Apr-03 10:47
professionalDuncan Edwards Jones22-Apr-03 10:47 
AnswerRe: Discretionary Access Control Lists (DACLs) - part of the .NET framework? Pin
Martin Cook24-Apr-03 7:51
professionalMartin Cook24-Apr-03 7:51 
GeneralCRLF vs LF in .NET?!?! Pin
moredip22-Apr-03 6:31
moredip22-Apr-03 6:31 
GeneralRe: CRLF vs LF in .NET?!?! Pin
moredip22-Apr-03 7:28
moredip22-Apr-03 7:28 
GeneralVisual Studio 7 customization Pin
pelloq121-Apr-03 4:09
pelloq121-Apr-03 4:09 
GeneralCopy local = False Pin
Patrick Lassalle21-Apr-03 3:41
Patrick Lassalle21-Apr-03 3:41 
GeneralRe: Copy local = False Pin
Martin Cook24-Apr-03 8:02
professionalMartin Cook24-Apr-03 8:02 
GeneralRe: Copy local = False Pin
Patrick Lassalle25-Apr-03 11:35
Patrick Lassalle25-Apr-03 11:35 
GeneralMetadata Format in PE Files Pin
Mike_V21-Apr-03 3:15
Mike_V21-Apr-03 3:15 
GeneralCrystal Reports/1.1 problems Pin
rondalescott18-Apr-03 12:30
rondalescott18-Apr-03 12:30 
GeneralQuickly Implement Interface methods Pin
Jamie Nordmeyer18-Apr-03 7:04
Jamie Nordmeyer18-Apr-03 7:04 
GeneralRe: Quickly Implement Interface methods Pin
Jamie Nordmeyer18-Apr-03 7:25
Jamie Nordmeyer18-Apr-03 7:25 
QuestionTracker Rect ? Pin
deemer17-Apr-03 21:08
deemer17-Apr-03 21:08 
GeneralPackaging and Distributing .NET DLL as CAB and referring methods within the same. Pin
Vasudevan Deepak Kumar17-Apr-03 19:51
Vasudevan Deepak Kumar17-Apr-03 19:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.