all groups > c# > june 2004 >
You're in the

c#

group:

arrays again


Re: arrays again Nicholas Paldino [.NET/C# MVP]
6/7/2004 11:02:59 AM
c#:
Eric,

Place a break in the debugger, and see what the types of the variables x
and y actually are. You might find that it is something you didn't expect.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

[quoted text, click to view]

Re: arrays again Jon Skeet [C# MVP]
6/7/2004 3:51:53 PM
[quoted text, click to view]

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
arrays again Eric Eggermann
6/7/2004 11:48:12 PM
Thanks for the help last week, but I've got a new problem with a different
array now.....sigh.
I want to use an ArrayList to hold unique integer arrays. I've written a
comparer class which works when I call the function explicitly, but when I
use the Sort and BinarySearch functions of my ArrayList object I get
InvalidCast exceptions.

public int Compare(object x, object y)
{
return Compare((Array)x, (Array)y); //InvalidCast exception here
}
public int Compare(Array x, Array y)
{
.... comparison code here is working....
}

Of course, the ArrayList only contains int[] arrays. Also, the above code is
just one of many equally useless tries I've had at this. How do I cast
between an object reference and an array of ints, so that I can use my
comparer with ArrayList.Sort and BinarySearch functions?

All ideas well appreciated,
Eric


Re: arrays again Eric Eggermann
6/8/2004 8:26:58 AM

"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:ebiZ4CKTEHA.3476@tk2msftngp13.phx.gbl...
[quoted text, click to view]
expect.

I have, and I find that both x, and y in Compare(object x, object y) are
System.Int32. Didn't really expect that. And the GetType().IsArray returns
false. So I'm still confused.


Eric

Re: arrays again Eric Eggermann
6/8/2004 8:52:18 AM

[quoted text, click to view]

While putting that demo program together, the silly thing seemed to work.
Still doesn't work in the place where I actually need it, but the problem
seems to be somewhere else. Got some work to do.

Thanks for the help, and I'll post that program when I manage to figure out
where the problem lies.

Eric

Re: arrays again Marko Becirevic
6/8/2004 2:36:45 PM

[quoted text, click to view]

maybe you send ints or pointers to beginning of an int array, not to the
beginning of an Array class.
Check code from where you call this method.

Re: arrays again Eric Eggermann
6/8/2004 11:48:58 PM
Thank for all the replies. They were much help and showed me that the bug
was in a different part of the program. It turned out that the comparer was
working, but I had used it with the wrong sort of object. I'd used it in
sorting an array of ints instead of an array of int arrays as it was
intended. Stupid oversight, but I'd needed your questions to help me find
that.

Cheers,
Eric

AddThis Social Bookmark Button