473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problems with ArrayList::ToArray

Hello

The following code does not work

ArrayList __gc* allControls = new ArrayList();
.....
// put some Controls in allControls
....
Control __gc* arr[] = dynamic_cast<Control
__gc*[]>(allControls->ToArray(__typeof(Control)));

The cast does not succeed and arr is NULL. This is a translated version of
some C# code I saw. So I think it is supposed to work. If I use allControls
directly and iterate through the array casting each item to Control __gc* it
also works. So the items in allControl are really of type Control __gc*.

Thanks

Nov 17 '05 #1
2 1337
Dirk,
The following code does not work

ArrayList __gc* allControls = new ArrayList();
....
// put some Controls in allControls
...
Control __gc* arr[] = dynamic_cast<Control
__gc*[]>(allControls->ToArray(__typeof(Control)));

The cast does not succeed and arr is NULL. This is a translated version of
some C# code I saw. So I think it is supposed to work. If I use allControls directly and iterate through the array casting each item to Control __gc* it also works. So the items in allControl are really of type Control __gc*.


This seems to work just fine for me....:
Control __gc* allControls2[] =
dynamic_cast<Control __gc*
__gc[]>(allControls->ToArray(__typeof(Control)));

I'm not quite sure what the problem could be.... have you tried checking
that indeed allControls->ToArray() is not returning NULL itself?

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #2
Hello
I'm not quite sure what the problem could be.... have you tried checking
that indeed allControls->ToArray() is not returning NULL itself?
allControls->ToArray() returns a valid System::Array, only the cast fails.
I also inserted a __try_cast to Control * for each item I put into the
ArrayList, so there are indeed only valid controls in the ArrayList.
"Tomas Restrepo (MVP)" <to****@mvps.org> wrote in message
news:O4**************@TK2MSFTNGP10.phx.gbl... Dirk,
The following code does not work

ArrayList __gc* allControls = new ArrayList();
....
// put some Controls in allControls
...
Control __gc* arr[] = dynamic_cast<Control
__gc*[]>(allControls->ToArray(__typeof(Control)));

The cast does not succeed and arr is NULL. This is a translated version of some C# code I saw. So I think it is supposed to work. If I use allControls
directly and iterate through the array casting each item to Control

__gc* it
also works. So the items in allControl are really of type Control __gc*.


This seems to work just fine for me....:
Control __gc* allControls2[] =
dynamic_cast<Control __gc*
__gc[]>(allControls->ToArray(__typeof(Control)));

I'm not quite sure what the problem could be.... have you tried checking
that indeed allControls->ToArray() is not returning NULL itself?
--
Tomas Restrepo
to****@mvps.org

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Oueis | last post by:
ArrayList arrayList = new ArrayList(); foreach (Blabla bla in Blablas) { arrayList.Add(Convert.ToInt32(blabla.something)); } so far this works great.. but now
2
by: Sunny | last post by:
Hi, I have a small function, that returns a string, inside the function, there is an arraylist, being processed. At the end of the function all the elements of the ArrayList are copied to my...
4
by: Derrick | last post by:
If i have an ArrayList, add a bunch of MyClass classes to it, how do I get a MyClass out of it? I've tried: MyClass clses = ArrayList.ToArray(typeof(MyClass)); but get errors about not being...
1
by: Jack Addington | last post by:
I have a method that takes an array of nodes (UltraNode) as a parameter. I've got an arrayList of objects that I am trying to convert to UltraNodes and pass to the method but I cannot seem to get...
2
by: Dylan Parry | last post by:
Hi, I have an ArrayList that contains objects of type "Client", and I would like to convert the ArrayList to a regular Array before returning it from a method. I would like to return it as an...
1
by: Tedmond | last post by:
Dear all, How can I convert a list of items from ArrayList into an array of non system type objects? e.g. The following codes have error: public class myClass { int i;
4
by: GB | last post by:
Hello: I have ArrayList strat_list of integers like this: index value 3 4 2 1 6
3
by: Michael Howes | last post by:
I have many double that each have a few thousand numbers in them. I need to concatenate groups of these double arrays into a new set of double. I don't know the total # of points. I thought it...
2
by: yongw99 | last post by:
I have an arraylist which has 0 number of elements. When i cast it to a string array, what happens ? Will my string be a "null" value, or will I get a ArgumentNullException ? eg. ArrayList al...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.