473,652 Members | 3,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9971
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******@hotma il.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.co m>
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 InfluenceCollec tion
InfluenceMatrix would hold only InfluenceCollec tion objects
That way, your code would look like this:

private InfluenceMatrix influences=new InfluenceMatrix ();
influences[x,y]=GetInfluences( ) // change GetInfluences to return
InfluenceCollec tion 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******@hotma il.com> wrote in message
news:10******** *******@newsrea der2.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
10118
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 code... TCHAR myArray; DoStuff(myArray);
22
4601
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 month I had enough of extra proof that the cat doesn't hount mice anymore in more and more situations. And the surrent sicretisme among array and hash is the base for it. I summarized all points in this article:...
7
7402
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 example, the manner in which I update element 1 depends on several other (randomly numbered) elements in the array. So, I can't change an element until I've figured out how every element changes.
21
3198
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 column. Once the array elements are split, what is the best way to sort them? Thank you. //populate data object with data from xml file. //Data is a comma delimited list of values var jsData = new Array(); jsData = {lib: "#field...
104
16929
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 that array Could you show me a little example how to do this? Thanks.
24
3437
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 declared an array as: char *stringArray = {"one","two","three","a"}; When I pass the array using:
57
3233
by: buuuuuum | last post by:
why array can't be assigned, like structs?
17
7239
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 to show the array data to the end user. Can I do that? How?
1
3104
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 a,b,c into another array f.. I can do two arrays, but I have issues when trying to do all three and when I do the even/odd compare I only get 2 numbers processed. here is some of the code... //*******************Function...
9
4493
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 function: x = new int;
0
8367
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8703
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
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 we have to send another system
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.