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

How to build an (list)array of types

Friends

Coming from vb I was used to do the following

private type AnyType
A as STRING
B as INTEGER
end Type

DIM anyArray() as AnyType

after giving the array a dimension like REDIM anyArray(1 to 10)
I was able to access any element as follows:

anyArray.A(1) = "MERCEDES"
anyArray.B(1) = "123"
anyArray.A(2) = "BMW"
anyArray.B(2) = "234"
etc

How can I achieve something like this in C#???
please help

Gerrit Esmeijer

Nov 16 '05 #1
4 2009
struct AnyType {
public string A;
public int B;
}

AnyType[] anyArray = new AnyType[10];

anyArray.A[0] = "MERCEDES";
anyArray.B[0] = 123;
anyArray.A[1] = "BMW";
anyArray.B[1] = 234;

I think this would work, however I haven't test it out yet.
If it doesn't work let me know

hope this help,

Du

"G.Esmeijer" <No***@nobody.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Friends

Coming from vb I was used to do the following

private type AnyType
A as STRING
B as INTEGER
end Type

DIM anyArray() as AnyType

after giving the array a dimension like REDIM anyArray(1 to 10)
I was able to access any element as follows:

anyArray.A(1) = "MERCEDES"
anyArray.B(1) = "123"
anyArray.A(2) = "BMW"
anyArray.B(2) = "234"
etc

How can I achieve something like this in C#???
please help

Gerrit Esmeijer


Nov 16 '05 #2
> anyArray.A[0] = "MERCEDES";
anyArray.B[0] = 123;
anyArray.A[1] = "BMW";
anyArray.B[1] = 234;
that supposes to look like the following

anyArray[0].A = "MERCEDES";
anyArray[0].B = 123;
anyArray[1].A = "BMW";
anyArray[1].B = 234;

copy and paste devil :-)
"Du Dang" <vi*******@hotmail.com> wrote in message
news:hN********************@nnrp1.uunet.ca... struct AnyType {
public string A;
public int B;
}

AnyType[] anyArray = new AnyType[10];

anyArray.A[0] = "MERCEDES";
anyArray.B[0] = 123;
anyArray.A[1] = "BMW";
anyArray.B[1] = 234;

I think this would work, however I haven't test it out yet.
If it doesn't work let me know

hope this help,

Du

"G.Esmeijer" <No***@nobody.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Friends

Coming from vb I was used to do the following

private type AnyType
A as STRING
B as INTEGER
end Type

DIM anyArray() as AnyType

after giving the array a dimension like REDIM anyArray(1 to 10)
I was able to access any element as follows:

anyArray.A(1) = "MERCEDES"
anyArray.B(1) = "123"
anyArray.A(2) = "BMW"
anyArray.B(2) = "234"
etc

How can I achieve something like this in C#???
please help

Gerrit Esmeijer



Nov 16 '05 #3
On Thu, 1 Apr 2004 15:19:19 -0500, Du Dang <vi*******@hotmail.com> wrote:
struct AnyType {
public string A;
public int B;
}

AnyType[] anyArray = new AnyType[10];

anyArray.A[0] = "MERCEDES";
anyArray.B[0] = 123;
anyArray.A[1] = "BMW";
anyArray.B[1] = 234;

I think this would work, however I haven't test it out yet.
If it doesn't work let me know


It's "anyArray" that is an array, not the A and B members of the type.
Thus to use it:

anyArray[0].A = "MERCEDES";
anyArray[0].B = 123;

etc.

I don't think VB allowed that syntax he showed either, I think the same
change as I showed here would have to be done to his code, but I'm not
100% sure.

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://www.vkarlsen.no/
PGP KeyID: 0x0270466B
Nov 16 '05 #4
There isn't a "redim" or such in C#, but you can create an of items like
this:

struct AnyType
{
public string A;
public int B;
}

AnyType[] anyArray = new AnyType[10];
anyArray[0].A = "Test";

- Noah Coad -
Microsoft MVP

P.S. I believe this is even easier... :)

"G.Esmeijer" <No***@nobody.nl> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Friends

Coming from vb I was used to do the following

private type AnyType
A as STRING
B as INTEGER
end Type

DIM anyArray() as AnyType

after giving the array a dimension like REDIM anyArray(1 to 10)
I was able to access any element as follows:

anyArray.A(1) = "MERCEDES"
anyArray.B(1) = "123"
anyArray.A(2) = "BMW"
anyArray.B(2) = "234"
etc

How can I achieve something like this in C#???
please help

Gerrit Esmeijer


Nov 16 '05 #5

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

Similar topics

1
by: OlgaM | last post by:
Hello, i'm trying to initialize an array. The class List contains this in its private data members: ListNode<DATATYPE> *dataItems; In the constructor, i'm trying to allocate space for...
7
by: Adam Hartshorne | last post by:
As a result of a graphics based algorihtms, I have a list of indices to a set of nodes. I want to efficiently identify any node indices that are stored multiple times in the array and the...
4
by: G.Esmeijer | last post by:
Friends Coming from vb I was used to do the following private type AnyType A as STRING B as INTEGER end Type DIM anyArray() as AnyType
7
by: Jim Lewis | last post by:
I'm trying to move a function into pyrex for speed. The python side needs to pass a list to the pyrex function. Do I need to convert to array or something so pyrex can generate tight code? I'm not...
5
by: bruce | last post by:
hi... i'm trying to deal with multi-dimension lists/arrays i'd like to define a multi-dimension string list, and then manipulate the list as i need... primarily to add lists/information to the...
2
by: Sean | last post by:
Hi I have the following code: struct node{ int ID; bool connected; int *connectedTo; int numConnectedTo; int numMsgsRecieved; int overwhelmed; node *nxtNode;
4
by: Kurien Mathew | last post by:
Hello, What will be a concise & efficient way to convert a list/array.array of n elements into a hex string? For e.g. given the bytes I would like the formatted string 0x74 0x6f 0x6e 0x67...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
0
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...

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.