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

Array of arrays

I need to make a two dimensional array of objects. These objects are of type
Influence[].
How do I declare such an array?

Now I use:
private object[,] influences;
influences[x, y] = GetInfluences(); // GetInfluences returns type
Influence[]

But when I need to use something from te array I have to typecast from
object to Influence[].
I would like to have a two dimensional array of type Influence[] in stead of
type object.

private Influence[][,] influences; // This does compile
influences[x, y] = GetInfluences(); // Compile error : Wrong number of
indices inside [], expected '1'

Does anyone have an idea?

Thanks in advance,
Kurzweil
Nov 15 '05 #1
3 9954
mk
Hi,
Look at your individual declarations, where you create
the initial object array, you declare it as [,]. Where
you create the Influences array, you declare it as [][,]!
Unless you've changed the GetInfluences() method, you're
not going to return the correct number of dimensions.
I suspect that this is just a syntax error on your part.

HTH,

martin
-----Original Message-----
I need to make a two dimensional array of objects. These objects are of typeInfluence[].
How do I declare such an array?

Now I use:
private object[,] influences;
influences[x, y] = GetInfluences(); // GetInfluences returns typeInfluence[]

But when I need to use something from te array I have to typecast fromobject to Influence[].
I would like to have a two dimensional array of type Influence[] in stead oftype object.

private Influence[][,] influences; // This does compile
influences[x, y] = GetInfluences(); // Compile error : Wrong number ofindices inside [], expected '1'

Does anyone have an idea?

Thanks in advance,
Kurzweil
.

Nov 15 '05 #2
Kurzweil <ra******@hotmail.com> wrote:

<snip>
I would like to have a two dimensional array of type Influence[] in stead of
type object.

private Influence[][,] influences; // This does compile
influences[x, y] = GetInfluences(); // Compile error : Wrong number of
indices inside [], expected '1'

Does anyone have an idea?


Yes - you've declared it the wrong way round. You meant:

private Influence[,][] influences;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #3
Hello,

I would suggest that you create a strongly typed collection to help simplify
things.

I would suggest two collections in this case:
InfluenceMatrix and InfluenceCollection
InfluenceMatrix would hold only InfluenceCollection objects
That way, your code would look like this:

private InfluenceMatrix influences=new InfluenceMatrix();
influences[x,y]=GetInfluences() // change GetInfluences to return
InfluenceCollection instead of Influence[]

There are many tools that generate strongly typed collections if you don't
want to write the boilerplate code yourself.
This allows you to separate interface from implementation in this case.
It also simplifies passing the data around in your program.
Finally, the collections themselves can be implemented using arrays so that
you have an O(1) get/set just like an array.
It will also simplify your documentation and make the users of the
collections much happier.

Oscar Papel.

"Kurzweil" <ra******@hotmail.com> wrote in message
news:10***************@newsreader2.wirehub.nl...
I need to make a two dimensional array of objects. These objects are of type Influence[].
How do I declare such an array?

Now I use:
private object[,] influences;
influences[x, y] = GetInfluences(); // GetInfluences returns type
Influence[]

But when I need to use something from te array I have to typecast from
object to Influence[].
I would like to have a two dimensional array of type Influence[] in stead of type object.

private Influence[][,] influences; // This does compile
influences[x, y] = GetInfluences(); // Compile error : Wrong number of
indices inside [], expected '1'

Does anyone have an idea?

Thanks in advance,
Kurzweil

Nov 15 '05 #4

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

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
7
by: simkn | last post by:
Hello, I'm writing a function that updates an array. That is, given an array, change each element. The trick is this: I can't change any elements until I've processed the entire array. For...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
57
by: buuuuuum | last post by:
why array can't be assigned, like structs?
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
1
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
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:
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
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.