English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a class idnamepair which contains 2 members, int id and String^ name;
I have a ArrayList created with this class's objects.
How can I convert it to array?

2007-03-04 22:09:42 · 3 answers · asked by hope_of_d_world 3 in Computers & Internet Programming & Design

converting an arraylist of string is very simple. I am having objects.
Anyways i got it myself:
array ^ arrRet = (array ^)arr->ToArray(arr[0]->GetType());

where arr is of type ArrayList.

2007-03-04 22:38:13 · update #1

3 answers

(idnamepair[]) yourArrayList.ToArray( typeof(idnamepair) )

2007-03-04 22:50:18 · answer #1 · answered by Sergi 2 · 0 0

Here's how in C#.

ArrayList MyArrayList = new ArrayList();
MyArrayList.Add( new idnamepair() ); //added first instance of your class
MyArrayList.Add( new idnamepair() ); //added another instance of your class

idnamepair[] MyArray;
MyArray = MyArrayList.ToArray( typeof(idnamepair) );

hope this helps

2007-03-05 07:04:15 · answer #2 · answered by Smutty 6 · 0 0

example
ArrayList a = new ArrayList();

a.Add("one");
a.Add("two");

Array b = a.ToArray(); // this function convers arraylist to array

result:
b[0]="one"
b[1]="two"

2007-03-05 06:28:08 · answer #3 · answered by rahul_Codes 2 · 0 0

fedest.com, questions and answers