473,402 Members | 2,050 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,402 software developers and data experts.

Arraylist of arrays

I have to create a arraylist of arrays. So, at the end, I have to
convert this arraylist in a two dimmensional array.

I wrote something like this.
ArrayList myAL = new ArrayList();
double[] cvt = new double[3];

cvt[0] = 0.0; cvt[1] = 1.01; cvt[2] = 2.02;
myAL.Add(cvt.Clone());

cvt[0] = 10.0; cvt[1] = 11.11; cvt[2] = 22.22;
myAL.Add(cvt.Clone());

double[] myInt = (double[]) myAL.ToArray(typeof(double[]));

But something is wrong when I convert the arraylist in a two
dimmensional array.

Is there a better way to do that?
What is wrong in the convertion line?

Thanks

Nov 6 '07 #1
3 4670
Hi Wolima,

Your last line is wrong. myAl contains a list of double[]. When you are calling ToArray() on myAl it doesn't return just a single double[] butan array of them. Change the last line to

double[][] myInt = (double[][])myAL.ToArray(typeof(double[]));

On Tue, 06 Nov 2007 18:20:00 +0100, wolima <wo******@gmail.comwrote:
I have to create a arraylist of arrays. So, at the end, I have to
convert this arraylist in a two dimmensional array.

I wrote something like this.
ArrayList myAL = new ArrayList();
double[] cvt = new double[3];

cvt[0] = 0.0; cvt[1] = 1.01; cvt[2] = 2.02;
myAL.Add(cvt.Clone());

cvt[0] = 10.0; cvt[1] = 11.11; cvt[2] = 22.22;
myAL.Add(cvt.Clone());

double[] myInt = (double[]) myAL.ToArray(typeof(double[]));

But something is wrong when I convert the arraylist in a two
dimmensional array.

Is there a better way to do that?
What is wrong in the convertion line?

Thanks



--
Happy coding!
Morten Wennevik [C# MVP]
Nov 6 '07 #2
Thanks Morten, for your help.

On 6 nov, 15:58, "Morten Wennevik [C# MVP]"
<MortenWenne...@hotmail.comwrote:
Hi Wolima,

Your last line is wrong. myAl contains a list of double[]. When you are calling ToArray() on myAl it doesn't return just a single double[] but an array of them. Change the last line to

double[][] myInt = (double[][])myAL.ToArray(typeof(double[]));

On Tue, 06 Nov 2007 18:20:00 +0100, wolima <wolim...@gmail.comwrote:
I have to create a arraylist of arrays. So, at the end, I have to
convert this arraylist in a two dimmensional array.
I wrote something like this.
ArrayList myAL = new ArrayList();
double[] cvt = new double[3];
cvt[0] = 0.0; cvt[1] = 1.01; cvt[2] = 2.02;
myAL.Add(cvt.Clone());
cvt[0] = 10.0; cvt[1] = 11.11; cvt[2] = 22.22;
myAL.Add(cvt.Clone());
double[] myInt = (double[]) myAL.ToArray(typeof(double[]));
But something is wrong when I convert the arraylist in a two
dimmensional array.
Is there a better way to do that?
What is wrong in the convertion line?
Thanks

--
Happy coding!
Morten Wennevik [C# MVP]- Ocultar texto entre aspas -

- Mostrar texto entre aspas -

Nov 6 '07 #3
wolima wrote:
I have to create a arraylist of arrays. So, at the end, I have to
convert this arraylist in a two dimmensional array.

I wrote something like this.
<snip>
double[] myInt = (double[]) myAL.ToArray(typeof(double[]));
As Morten said, in this line you want to be casting to double[][].

It should be pointed out that ArrayList is basically obsolete. If you
had used List<double[]instead, you would have got a nice meaningful
compiler error. :-)

Alun Harford
Nov 6 '07 #4

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

Similar topics

2
by: Vaden95 | last post by:
I am trying to uae ArrayList to store arrays of structures, but I can't get my data back after storing the arrays. My (highly shrunk and modified) code is below. The problem is at the line labled...
1
by: Jamus Sprinson | last post by:
Before I continue, I'm going to begin by saying I'm not by any means an expert- I've been using .NET with C# for about 4 months now, and basically just learning by example and docs. A game...
3
by: george r smith | last post by:
I am trying to create an arrayList that contains multiple arrayLists. My code attempt is below. The question I have is how can I get away from creating another pAttribute list than can be added to...
5
by: Kevin | last post by:
Hi All Can someone please tell me the difference between an Array and an ArrayList, and where I would be likely to use one over the other Thanks alot for any help
4
by: Ricardo | last post by:
how can i acess the members of an array that i put into a arraylist, like this: int dez = new int; ArrayList arList = new ArrayList(); arList.add(dez); I want to get the dez value.
2
by: D. Shane Fowlkes | last post by:
I've been reading up on Arrays in ASP.NET. I'm going to create an two dimensional array of some type to contain 5 columns but a variable amount of rows. I read up on the ArrayList function and...
3
by: Zenon | last post by:
I have a function which returns array of structs. I need to create a collection of those arrays and thought that an ArrayList would be a good way to do this since the count is variable. The...
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...
20
by: cowboyrocks2009 | last post by:
Hi, I need help to automate my code to take data from input file. Also I need to create it as a function so that I can pass it to some other program. I am new to Java so having a bit limitation to...
1
by: cowboyrocks2009 | last post by:
Hi. I want to return values from multiple Arraylist. How can I do that ? later I want to use these values in another class. Can somebody help class myClass{ public ArrayList<Rectangle>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.