473,701 Members | 2,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multidimensiona l Arrays??

Hi,
I wish to parse an XML file into some sort or array or multidimensiona l storage. The XML file is as follows (without any parent tags just to give you an idea of the structure)...
<Ship Name="Disrupter " Class="CC" PrimaryTarget=" CR" BattleOrder="1" Guns="5" Power="2"></Ship>
<Ship Name="Zealot" Class="CR" PrimaryTarget=" CC" BattleOrder="2" Guns="25" Power="5"></Ship>
<Ship Name="Drone" Class="CC" PrimaryTarget=" CC" BattleOrder="3" Guns="4" Power="2"></Ship>
<Ship Name="Invader" Class="CC" PrimaryTarget=" CO" BattleOrder="4" Guns="3" Power="4"></Ship>
<Ship Name="Reformer" Class="CO" PrimaryTarget=" FR" BattleOrder="5" Guns="5" Power="6"></Ship>

In PHP (my primary programming langugage) I would be able to create a multidimensiona l array that that woudl look something like this...

[0] ->
[Name] = "Disrupter"
[Class] = "CC"
[PrimaryTarget] = "CR"
[BattleOrder] = "1"
[Guns] = "5"
[Power] = "2"

[1] ->
[Name] = "Zealot"
[Class] = "CR"
[PrimaryTarget] = "CC"
[BattleOrder] = "2"
[Guns] = "25"
[Power] = "5"

etc...

I understand that you can't have text identifiers for array values in C# like you can in PHP. Can anyone suggest anything?

Thanx Josh

Nov 15 '05 #1
11 2096
Joshua Russell wrote:
Hi,
I wish to parse an XML file into some sort or array or multidimensiona l
storage. The XML file is as follows (without any parent tags just to
give you an idea of the structure)...

<Ship Name="Disrupter " Class="CC" PrimaryTarget=" CR" BattleOrder="1"
Guns="5" Power="2"></Ship>
<Ship Name="Zealot" Class="CR" PrimaryTarget=" CC" BattleOrder="2"
Guns="25" Power="5"></Ship>
<Ship Name="Drone" Class="CC" PrimaryTarget=" CC" BattleOrder="3"
Guns="4" Power="2"></Ship>
<Ship Name="Invader" Class="CC" PrimaryTarget=" CO" BattleOrder="4"
Guns="3" Power="4"></Ship>
<Ship Name="Reformer" Class="CO" PrimaryTarget=" FR" BattleOrder="5"
Guns="5" Power="6"></Ship>

In PHP (my primary programming langugage) I would be able to create a
multidimensiona l array that that woudl look something like this...

*[0]* ->
* **[Name]* = "Disrupter"
* **[Class]* = "CC"
* **[PrimaryTarget]* = "CR"
*[BattleOrder] *= "1"
* **[Guns]* = "5"
* **[Power]* = "2"

*[1]* ->
* **[Name]* = "Zealot"
* **[Class]* = "CR"
* **[PrimaryTarget]* = "CC"
*[BattleOrder]* = "2"
*[Guns]* = "25"
*[Power]* = "5"

etc...

I understand that you can't have text identifiers for array values in C#
like you can in PHP. Can anyone suggest anything?

Thanx Josh

Use a System.Collecti ons.Hashtable.

Hashtable ships = new Hashtable();
ships["Name"] = "Zealot";
// etc.

Nov 15 '05 #2
Hashtable....

Thx

"Tyler Dixon" <td****@telus.n et> wrote in message
news:oW9xb.3039 4$oN2.21799@edt nps84...
Joshua Russell wrote:
Hi,
I wish to parse an XML file into some sort or array or multidimensiona l
storage. The XML file is as follows (without any parent tags just to
give you an idea of the structure)...

<Ship Name="Disrupter " Class="CC" PrimaryTarget=" CR" BattleOrder="1"
Guns="5" Power="2"></Ship>
<Ship Name="Zealot" Class="CR" PrimaryTarget=" CC" BattleOrder="2"
Guns="25" Power="5"></Ship>
<Ship Name="Drone" Class="CC" PrimaryTarget=" CC" BattleOrder="3"
Guns="4" Power="2"></Ship>
<Ship Name="Invader" Class="CC" PrimaryTarget=" CO" BattleOrder="4"
Guns="3" Power="4"></Ship>
<Ship Name="Reformer" Class="CO" PrimaryTarget=" FR" BattleOrder="5"
Guns="5" Power="6"></Ship>

In PHP (my primary programming langugage) I would be able to create a
multidimensiona l array that that woudl look something like this...

*[0]* ->
* **[Name]* = "Disrupter"
* **[Class]* = "CC"
* **[PrimaryTarget]* = "CR"
*[BattleOrder] *= "1"
* **[Guns]* = "5"
* **[Power]* = "2"

*[1]* ->
* **[Name]* = "Zealot"
* **[Class]* = "CR"
* **[PrimaryTarget]* = "CC"
*[BattleOrder]* = "2"
*[Guns]* = "25"
*[Power]* = "5"

etc...

I understand that you can't have text identifiers for array values in C#
like you can in PHP. Can anyone suggest anything?

Thanx Josh

Use a System.Collecti ons.Hashtable.

Hashtable ships = new Hashtable();
ships["Name"] = "Zealot";
// etc.

Nov 15 '05 #3
>
Use a System.Collecti ons.Hashtable.

Hashtable ships = new Hashtable();
ships["Name"] = "Zealot";
// etc.


While that will do what he was trying to do (or at least, an Array of
HashTables would do it), I can hardly condone that sort of data structure.
It seems as if each item in the array has a certain number of properties.
Why not make a Ship class with a Name, ShipClass, PrimaryTarget,
BattleOrder, Guns, and Power properties?

Then you could make a ShipCollection class, if you wanted. Or an Ship[]
array may suffice.

Is there any real reason to want these in a "multi-dimensional array," or is
it just because that's the way you're used to doing it?

Having to look up each of these values in a hash-table would hurt
performance a bit, and you would lose any help from the IDE (IntelliSense).

If you're interested in making a Ship class, but don't know how, then I'll
be glad to help.
--Matthew W. Jackson
Nov 15 '05 #4
Yeah, I'm pretty new to C# so if you could help me make a Ships[] class that
woudl be appreciated.

Thanx Josh
"Matthew W. Jackson" <th************ ********@NOSPAM .NOSPAM> wrote in message
news:O9******** ******@TK2MSFTN GP12.phx.gbl...

Use a System.Collecti ons.Hashtable.

Hashtable ships = new Hashtable();
ships["Name"] = "Zealot";
// etc.

While that will do what he was trying to do (or at least, an Array of
HashTables would do it), I can hardly condone that sort of data structure.
It seems as if each item in the array has a certain number of properties.
Why not make a Ship class with a Name, ShipClass, PrimaryTarget,
BattleOrder, Guns, and Power properties?

Then you could make a ShipCollection class, if you wanted. Or an Ship[]
array may suffice.

Is there any real reason to want these in a "multi-dimensional array," or

is it just because that's the way you're used to doing it?

Having to look up each of these values in a hash-table would hurt
performance a bit, and you would lose any help from the IDE (IntelliSense).
If you're interested in making a Ship class, but don't know how, then I'll
be glad to help.
--Matthew W. Jackson

Nov 15 '05 #5
Yeah, I'm pretty new to C# so if you could help me make a Ships[] class that
woudl be appreciated.

Thanx Josh
"Matthew W. Jackson" <th************ ********@NOSPAM .NOSPAM> wrote in message
news:O9******** ******@TK2MSFTN GP12.phx.gbl...

Use a System.Collecti ons.Hashtable.

Hashtable ships = new Hashtable();
ships["Name"] = "Zealot";
// etc.

While that will do what he was trying to do (or at least, an Array of
HashTables would do it), I can hardly condone that sort of data structure.
It seems as if each item in the array has a certain number of properties.
Why not make a Ship class with a Name, ShipClass, PrimaryTarget,
BattleOrder, Guns, and Power properties?

Then you could make a ShipCollection class, if you wanted. Or an Ship[]
array may suffice.

Is there any real reason to want these in a "multi-dimensional array," or

is it just because that's the way you're used to doing it?

Having to look up each of these values in a hash-table would hurt
performance a bit, and you would lose any help from the IDE (IntelliSense).
If you're interested in making a Ship class, but don't know how, then I'll
be glad to help.
--Matthew W. Jackson

Nov 15 '05 #6
One other possibility, depending on how you wish to use this, is to use a DataTable (part of the System.Data namespace in ADO.NET). There may be a way to automatically create a DataTable (i.e., a 2 dimensional array-like thing) out of your existing XML file.

"Joshua Russell" <jo**@ojmyster. uk.eu.org> wrote in message news:eY******** ******@tk2msftn gp13.phx.gbl...
Hi,
I wish to parse an XML file into some sort or array or multidimensiona l storage. The XML file is as follows (without any parent tags just to give you an idea of the structure)...
<Ship Name="Disrupter " Class="CC" PrimaryTarget=" CR" BattleOrder="1" Guns="5" Power="2"></Ship>
<Ship Name="Zealot" Class="CR" PrimaryTarget=" CC" BattleOrder="2" Guns="25" Power="5"></Ship>
<Ship Name="Drone" Class="CC" PrimaryTarget=" CC" BattleOrder="3" Guns="4" Power="2"></Ship>
<Ship Name="Invader" Class="CC" PrimaryTarget=" CO" BattleOrder="4" Guns="3" Power="4"></Ship>
<Ship Name="Reformer" Class="CO" PrimaryTarget=" FR" BattleOrder="5" Guns="5" Power="6"></Ship>

In PHP (my primary programming langugage) I would be able to create a multidimensiona l array that that woudl look something like this...

[0] ->
[Name] = "Disrupter"
[Class] = "CC"
[PrimaryTarget] = "CR"
[BattleOrder] = "1"
[Guns] = "5"
[Power] = "2"

[1] ->
[Name] = "Zealot"
[Class] = "CR"
[PrimaryTarget] = "CC"
[BattleOrder] = "2"
[Guns] = "25"
[Power] = "5"

etc...

I understand that you can't have text identifiers for array values in C# like you can in PHP. Can anyone suggest anything?

Thanx Josh

Nov 15 '05 #7
//here ya go
public struct Ship
{
#region Private Fields
private string name;
private Class classtype;
private Primary target;
private int battleorder, guns, power;
#endregion

#region Enums
public enum Class
{
CC,
CR,
CO
//add more if needed
}

public enum Primary
{
CR,
CC,
CO,
FR
}
#endregion

#region Constructor
public Ship(string name, Class ClassType, Primary target, int
BattleOrder, int Guns,int Power)
{
this.name=name;
this.classtype= ClassType;
this.target=tar get;
this.battleOrde r=BattleOrder;
this.guns=Guns;
this.power=Powe r;
}
#endregion

#region Public Properties
public string Name
{
get
{
return this.name;
}
set
{
if (value!=null)
this.name=value ;
}
}
public Class ClassType
{
get
{
return this.classtype;
}
set
{
this.classtype= value;
}
}

public Primary Target
{
get
{
return this.target;
}
set
{
this.target=val ue;
}
}

public int BattleOrder
{
get
{
return this.battleorde r;
}
set
{
this.battleorde r=value;
}
}

public int Guns
{
get
{
return this.guns;
}
set
{
this.guns=value ;
}
}

public int Power
{
get
{
return this.power;
}
set
{
this.power=valu e;
}
}
#endregion

}

On Wed, 26 Nov 2003 22:54:01 -0000, "Joshua Russell"
<jo**@ojmyster. uk.eu.org> wrote:
Yeah, I'm pretty new to C# so if you could help me make a Ships[] class that
woudl be appreciated.

Thanx Josh


Nov 15 '05 #8
Example??

"Mountain Bikn' Guy" <vc@attbi.com > wrote in message news:Rmcxb.3165 62$Tr4.987830@a ttbi_s03...
One other possibility, depending on how you wish to use this, is to use a DataTable (part of the System.Data namespace in ADO.NET). There may be a way to automatically create a DataTable (i.e., a 2 dimensional array-like thing) out of your existing XML file.

"Joshua Russell" <jo**@ojmyster. uk.eu.org> wrote in message news:eY******** ******@tk2msftn gp13.phx.gbl...
Hi,
I wish to parse an XML file into some sort or array or multidimensiona l storage. The XML file is as follows (without any parent tags just to give you an idea of the structure)...
<Ship Name="Disrupter " Class="CC" PrimaryTarget=" CR" BattleOrder="1" Guns="5" Power="2"></Ship>
<Ship Name="Zealot" Class="CR" PrimaryTarget=" CC" BattleOrder="2" Guns="25" Power="5"></Ship>
<Ship Name="Drone" Class="CC" PrimaryTarget=" CC" BattleOrder="3" Guns="4" Power="2"></Ship>
<Ship Name="Invader" Class="CC" PrimaryTarget=" CO" BattleOrder="4" Guns="3" Power="4"></Ship>
<Ship Name="Reformer" Class="CO" PrimaryTarget=" FR" BattleOrder="5" Guns="5" Power="6"></Ship>

In PHP (my primary programming langugage) I would be able to create a multidimensiona l array that that woudl look something like this...

[0] ->
[Name] = "Disrupter"
[Class] = "CC"
[PrimaryTarget] = "CR"
[BattleOrder] = "1"
[Guns] = "5"
[Power] = "2"

[1] ->
[Name] = "Zealot"
[Class] = "CR"
[PrimaryTarget] = "CC"
[BattleOrder] = "2"
[Guns] = "25"
[Power] = "5"

etc...

I understand that you can't have text identifiers for array values in C# like you can in PHP. Can anyone suggest anything?

Thanx Josh

Nov 15 '05 #9
My fault. I forgot that you're loading this data from XML, and need a
String-to-Enumeration conversion.

Luckily, the .NET framework can do this for you, although it's not quite as
strightforward as parsing numbers.

The code for loading the two enumerations would be as follows:

ships[i].ShipClass = (ShipClass)Enum .Parse(typeof(S hipClass), reader.Value,
true);

ships[i].PrimaryTarget = (ShipClass)Enum .Parse(typeof(S hipClass),
reader.Value, true);

And by the way, I would change all the "Int16.Pars e" calls to "Int32.Pars e",
since you are parsing values to be stored in an "int" property (which maps
to "System.Int32") . If you really want to use "Int16" (and that's fine, if
your values will never exceed 32K), then change the Ship class to use
"short" or "Int16" (same thing) on those fields instead of "int".

Let me know if there's anything else keeping your program from working. I
didn't actually load it up in VisualStudio and run it...just glazed over it
in Notepad.
"Joshua Russell" <joshATojmyster |DOTukDOTTeuDOO TorgNOSPAM.PLZ> wrote in
message news:OU******** ******@TK2MSFTN GP09.phx.gbl...
Hi,
Thanxs for that. I can't seem to get it to work tho. I thinik I'm using PHP principals...
Would you mind looking through my source? I have attached it.

Thx

"Matthew W. Jackson" <th************ ********@NOSPAM .NOSPAM> wrote in message news:cW******** ***********@twi ster.austin.rr. com...
Here's some code to get you started. I made a few assumptions about the
ranges of certain values (where I throw the ArgumentOutOfRa ngeException).
I didn't include any of the code to load the XML, because there are

several
good ways to do it (Xml Reader, Xml DOM, Dataset, Xml Fast Reader,
Serializer, etc.).

But this will certainly be better than an Array of Hashtables, for
performance, memory, and readability.

You may want to use an ArrayList instead of the Ship[] if you plan on

adding
a variable number of ships to the collection. I don't want to tell you

what
to do because I don't know enough about your project. I personally would write my own collection (ShipCollection ), and there are several examples
online describing how to use CollectionBase to do this (although I must
admit that many are incorrect since they don't implement OnValidate---but I'm off topic).

If you have trouble with the attachment, let mw know and I'll find another way to send it.

--Matthew W. Jackson


Nov 15 '05 #10

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

Similar topics

5
6753
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would clearly be the most efficient way to do it, but it only works on a copy of the original array and not the original (which is counter intuitive in my estimation). Using each doesn't work consistently either. Not only that, it's unduly complex for...
2
1137
by: Terry | last post by:
Hi, can someone plz tell me how multidimensional arrays (like a 2-D array) are stored in memory? Are they like single dimensional arrays? Stored sequentially in one "row", so to say? Thanks Terry
9
6668
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the function (which was translated from Fortran code), among other heinous and numerous declarations, is this bit: static float bbuff; static int bkey; static int buse;
3
8193
by: Claire | last post by:
I have a multidimensional array defined as private double myArray = new double; The first column of the array contains X values, the other contains Y values I have a charting function defined as Add(Array XValues, Array YValues) How do I call the Add function, passing my array columns please. thanks
3
2198
by: Ravi Singh (UCSD) | last post by:
Hello all I am trying to use jagged and multi-dimensional arrays in C++. In C# these work fine // for jagged arrays string jaggedArray = new string ; //for multidimensional arrays string multidimensionalArray = new string
21
4185
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if possible. The thing I am trying to do is to convert a double value to a string with 8 elements. 8 is fixed because of the files I work with. I will change this 8 character string with the one(8 character string) already in the file and so on. But I...
10
12203
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to help do the most basic things. One of the "basic" things I haven't been able to find out how to do is how to delete an item from a multidimensional array object and resize it afterwards. It seems so easy to conceive of the code to delete...
2
4483
by: oopsatwork | last post by:
Ok...so, I have been outside of the C world for a _very_ long time...but not so long as to remember how to do multidimensional arrays. So, let me state that I know how to malloc pointers to pointers and then malloc my data space. This question is NOT about that. I need to keep a dynamically sized (a result of command line options) matrix in a shared memory segment created via shmget and attached via shmat. My first instinct was to do...
12
5650
by: filippo nanni | last post by:
Hello everybody, my question is this: I have two multidimensional arrays and I have to create a third one (for later use) from comparing these two. Here is my example code: //BEGIN CODE var myGroups = ,,]; var myProducts = ,,,]; var newGroups = new Array();//Resulting Array function main() { for(i=0; i<myGroups.length; i++){
9
4496
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
8649
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
9232
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9084
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...
0
7827
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6573
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
4411
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...
1
3104
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
2399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2036
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.