By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,650 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,650 IT Pros & Developers. It's quick & easy.

Struct Array, Arraylist.Copyto() (InvalidCastException)

P: n/a
Hello All:
Having a problem with arraylist.copyto function. And here's a
sample of my code:
In global-->
public struct point
{
int x;
string y;
}
static public point point;
static public point pointarray[];
static public Arraylist myal = new Arraylist();

in sub_function -->
for (i=0; i< some limites; i++)
{
global.point[i].x = some limites.some value;
global.point[i].y = some limites.some string;
global.myal.Add(global.point);
}

in Main function -->

int a;
string b;

global.pointarray = new global.point[global.myal.Count];
global.myal.Copyto(pointarray);
for (i=0; i<global.myal.count; i++)
{
a = pointarray[i].x;
b = pointarray[i].y;
}

global.myal.Clear();
pointarray = null;

This is basically the logic of the steps that I am trying to make a
dynamic array struct, of course I understand there are different ways
of doing this, but this one seems easiest if I was to pick and choose
what needed to be inserted into my arraylist in main / sub function. It
works fine on my computer (xp pro .net 2.0), however it doesn't work on
my company's server computer (running server2003.net 2.0) Saying there
there is a casting exception on the global.myal.Copyto(pointarray)
statement. I spend a lot of time trying to understand why this differ
from machine to machine. But came up with nothing in MSDN or other
resources. Have anyone done something like this? Please let me know!!
Thank You!

Also, it keep on telling me that I have a casting problem, so I tried
to explicitly cast the array out of arraylist instead of copyto()..
Doesn't work either. Any ideas how to do that? Very much appreciated
it!!

Aug 29 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Can Any one Help???

Aug 30 '06 #2

P: n/a
<pe******@yahoo.comwrote:
Can Any one Help???
I'm sure they can, but you'll need to be more patient. Things are also
likely to be faster if you post a short but complete program
demonstrating your problem instead of just snippets.

See http://www.pobox.com/~skeet/csharp/complete.html for details.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.