473,320 Members | 1,933 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,320 software developers and data experts.

How to iterate the second dimension of a 2-dimensional array?

Hello,

I want to iterate the second dimension of a 2-dim-array.

Let´s say I have an array:

double[,] myArray and a given index: int i.

Assume my index is given in want to iterate my array with something like
this:
int i = 2;
double sum= 0.0;

for(int j = 0; j < myArray[i].Length; j++)
sum += myArray[i,j];

But this does not work, because I am using the 2dim-array as 1dim-array.
My problem is... how do i get the size of the second dimension?
Regards,

Martin
Sep 26 '06 #1
5 2670

Martin Pöpping wrote:
Hello,

I want to iterate the second dimension of a 2-dim-array.

Let´s say I have an array:

double[,] myArray and a given index: int i.

Assume my index is given in want to iterate my array with something like
this:
int i = 2;
double sum= 0.0;

for(int j = 0; j < myArray[i].Length; j++)
sum += myArray[i,j];

But this does not work, because I am using the 2dim-array as 1dim-array.
My problem is... how do i get the size of the second dimension?
Regards,

Martin
double[,] a=new double[10,10];

for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
a[i,j]=i*j;
}
}
//or try
foreach(double d in a)
{
Console.WriteLine(d.ToString());
}

Sep 26 '06 #2
DeveloperX schrieb:
double[,] a=new double[10,10];

for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
a[i,j]=i*j;
}
}
Well maybe you missunderstand my problem.
I do not know the second dimension.
In your example.... I do not know that j = 10.
//or try
foreach(double d in a)
{
Console.WriteLine(d.ToString());
}
If it would work... it would traverse the whole dimensional array.

I only want to work on a[2,j] for example.
Regards,

Martin

Sep 26 '06 #3
Martin P?pping <ma******@despammed.comwrote:
I want to iterate the second dimension of a 2-dim-array.

Let?s say I have an array:

double[,] myArray and a given index: int i.

Assume my index is given in want to iterate my array with something like
this:
int i = 2;
double sum= 0.0;

for(int j = 0; j < myArray[i].Length; j++)
sum += myArray[i,j];

But this does not work, because I am using the 2dim-array as 1dim-array.
My problem is... how do i get the size of the second dimension?
Use Array.GetLength(int dimension)

--
Jon Skeet - <sk***@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
Sep 26 '06 #4
Martin,

If you don't know anything about the array then you need to use the Array
class method and properties. Array is a base class for all arrays and as
such all arrays have them.
Check MSDN docs. Here are some usefull methods and proeprties that you may
want to use:
- Length (property) - total number of elements in all dimensions
- Rank (property) - number of dimensions
- GetLength (method) - return number of element is a specified dimension.
--
HTH
Stoitcho Goutsev (100)

"Martin Pöpping" <ma******@despammed.comwrote in message
news:ef**********@newsreader2.netcologne.de...
DeveloperX schrieb:
>double[,] a=new double[10,10];

for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
a[i,j]=i*j;
}
}

Well maybe you missunderstand my problem.
I do not know the second dimension.
In your example.... I do not know that j = 10.
>//or try
foreach(double d in a)
{
Console.WriteLine(d.ToString());
}

If it would work... it would traverse the whole dimensional array.

I only want to work on a[2,j] for example.
Regards,

Martin

Sep 26 '06 #5
In addition there is

GetUpperBound(dimension), returning the last index (length - 1)
On Tue, 26 Sep 2006 16:04:32 +0200, Stoitcho Goutsev (100) <10*@100.com>
wrote:
Martin,

If you don't know anything about the array then you need to use the Array
class method and properties. Array is a base class for all arrays and as
such all arrays have them.
Check MSDN docs. Here are some usefull methods and proeprties that you
may
want to use:
- Length (property) - total number of elements in all dimensions
- Rank (property) - number of dimensions
- GetLength (method) - return number of element is a specified dimension.



--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 26 '06 #6

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

Similar topics

9
by: Steve Jorgensen | last post by:
Hi all, I'm working on the schema for a database that must represent data about stock & bond funds over time. My connundrum is that, for any of several dimension fields, including the fund name...
1
by: Sara | last post by:
I am trying to use MDX to dynamically determine which hierarchy of the time dimension is selected. I have a calculated member which is using the last non-empty descendant of the . dimension, but...
0
by: vsridhar420 | last post by:
I am trying to create a local cube from a cube which has a parant child dimension. Is the syntax for DIMENSION clause in the CREATE CUBE statement different for a parent-child dimension ? Because...
2
by: SRL | last post by:
Hi, This is probably a classic scenario with a shared dimension that we need to use in different cubes, where all fact tables do not offer the same level of detail. Dimension is snow-flaked. ...
2
by: Tommo | last post by:
Chaps, Could someone please provide me some examples of iterating through a multimap. I wish to do the following 1. Iterate through each key in the multimap 2. For each key i find get all the...
4
dshimer
by: dshimer | last post by:
I have a file whose structure in strictly generic terms is similar to the following.keyname first keyword1 1.1 keyword2 1.2 keyword3 1.3 keyname second keyword1 2.1 keyword2 2.2 keyword3 2.3...
2
by: Efrat Regev | last post by:
Hello, Let's say a probability vector of dimension d is x_1, ..., x_d, where each one is a non-negative term, and they all sum up to 1. Now I'd like to iterate over all probability vectors, but...
0
by: Mike K | last post by:
I asked this question in the OLAP group but got no response. I am hoping somebody will have some answers here. Thanks ------------------- HI, I need to create a dimension that will play off...
6
by: notnorwegian | last post by:
i have a big file with sentences, the first file of each sentence contains a colon(:) somewher eon that line i want to jump past that sentence. if all(x != ':' for x in line): this way i can...
1
by: evelina | last post by:
Hello, I need help. I have the following hashmap: HashMap<HashMap<Dimension, Integer>, String> mapList = new HashMap<HashMap<Dimension, Integer>, String>(); I want to extract Dimesion from the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.