473,471 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with arrays

Hi,
I have a two dimensional array as follows:

double[,] myArray = new double[14, 41];

Now I have a method which is returning double[], which is of size 41.

I need to put the data of the array returned into myArray.
myArray[0, ???] = myMethod1(); // return double[41]
myArray[1, ???] = myMethod2(); // return double[41]
etc

I hope someone understands my problem and can help me out.
Thanks in Advance
Nov 16 '05 #1
2 1035
You're going to have to copy them in a loop. I threw together this function
which should make it a simple task.
public void CopyToArray(double[] sourceArray, double[,] destinationArray,
int destinationArrayIndex)
{
Debug.Assert(sourceArray.Length == destinationArray.GetLength(1)); //
make sure the to/from arrays are the same length

for (int i=0; i<sourceArray.Length; i++)
{
destinationArray[destinationArrayIndex, i] = sourceArray[i];
}
}

And in your case, you would call it like this:

CopyToArray(myMethod1(), myArray, 0);

ShaneB

"Xarky" <be*********@yahoo.com> wrote in message
news:bc*************************@posting.google.co m...
Hi,
I have a two dimensional array as follows:

double[,] myArray = new double[14, 41];

Now I have a method which is returning double[], which is of size 41.

I need to put the data of the array returned into myArray.
myArray[0, ???] = myMethod1(); // return double[41]
myArray[1, ???] = myMethod2(); // return double[41]
etc

I hope someone understands my problem and can help me out.
Thanks in Advance

Nov 16 '05 #2
You can use jagged arrays. For example double [][] myArray; You can then
assign like this: myArray[i]=myMethod(); Assumes myMethod returns double[].
Basically jagged arrays are arrays of arrays.

Thomas P. Skinner [MVP]
"ShaneB" <st********@yahoo.com> wrote in message
news:uR**************@TK2MSFTNGP11.phx.gbl...
You're going to have to copy them in a loop. I threw together this
function which should make it a simple task.
public void CopyToArray(double[] sourceArray, double[,] destinationArray,
int destinationArrayIndex)
{
Debug.Assert(sourceArray.Length == destinationArray.GetLength(1));
// make sure the to/from arrays are the same length

for (int i=0; i<sourceArray.Length; i++)
{
destinationArray[destinationArrayIndex, i] = sourceArray[i];
}
}

And in your case, you would call it like this:

CopyToArray(myMethod1(), myArray, 0);

ShaneB

"Xarky" <be*********@yahoo.com> wrote in message
news:bc*************************@posting.google.co m...
Hi,
I have a two dimensional array as follows:

double[,] myArray = new double[14, 41];

Now I have a method which is returning double[], which is of size 41.

I need to put the data of the array returned into myArray.
myArray[0, ???] = myMethod1(); // return double[41]
myArray[1, ???] = myMethod2(); // return double[41]
etc

I hope someone understands my problem and can help me out.
Thanks in Advance


Nov 16 '05 #3

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

Similar topics

6
by: Fnark! | last post by:
I am creating a shopping cart using PHP Version 4.1.2. I am creating and registering a cart object in a session. The cart object contains an array of arrays called $order whose elements are a...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
1
by: codergem | last post by:
The following code is for heap sort but its not working properly. According to my analysis the Logic is correct but still its not showing the correct output. Thanks. #include "stdafx.h"...
4
by: sonjaa | last post by:
Hi last week I posted a problem with running out of memory when changing values in NumPy arrays. Since then I have tried many different approaches and work-arounds but to no avail. I was...
3
by: MariyaGel | last post by:
I have wrote the program and it worked fine until I had to include one more array into it. As you can see below the two arrays of volume and mass are working properly now I need to include a third...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
19
by: rmr531 | last post by:
First of all I am very new to c++ so please bear with me. I am trying to create a program that keeps an inventory of items. I am trying to use a struct to store a product name, purchase price,...
43
by: John | last post by:
Hi This .net is driving me crazy!! In VB6 I had a type which contained a couple of multi-dimentional arrays which i used to create and read records: Type AAA : Array1(10,10,2) as Integer
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.