Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

Struct Array, Arraylist.Copyto() (InvalidCastException)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pengbsam@yahoo.com - 29 Aug 2006 21:27 GMT
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!!
pengbsam@yahoo.com - 30 Aug 2006 02:51 GMT
Can Any one Help???
Jon Skeet [C# MVP] - 30 Aug 2006 05:11 GMT
> 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.

Signature

Jon Skeet - <skeet@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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.