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

[Array] How Index from Name ?

tim
I have an array.

I have the name of an element.
I need the related index.

Is there a sort of "GetIndex" method
or I have to use the For Next cicle
until I met the given name?
Sep 19 '05 #1
10 1415
Tim,

The index you make yourself for an array.

by instance in VBNet
for i as integer = 0 to myArray.Length - 1
'do what you want
next

C#
For (int i=0;i<myArray.Lenght;i++){//do what you want}

Did you know by the way that there are special language newsgroups.
microsoft.public.dotnet.languages.vb or csharp or vs

I hope this helps,

Cor

"tim" <ti*@inwind.it> schreef in bericht
news:43************@news.tariffenet.it...
I have an array.

I have the name of an element.
I need the related index.

Is there a sort of "GetIndex" method
or I have to use the For Next cicle
until I met the given name?

Sep 19 '05 #2
>Is there a sort of "GetIndex" method

Array.IndexOf(yourArray, yourName)
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 19 '05 #3
tim <ti*@inwind.it> wrote:
I have an array.

I have the name of an element.


What exactly do you mean by the "name" of the element? If you mean the
name of a variable which was used to populate the array, that has no
meaning to the object itself which is referred to by the element.

--
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 19 '05 #4
Mattias Sjögren <ma********************@mvps.org> wrote:
Is there a sort of "GetIndex" method


Array.IndexOf(yourArray, yourName)


That would find the index of the *value* though. I *suspect* the OP
wants to be able to do:

string x = "hello";
string y = "there";

string[] array = new string[2];
array[x] = 0;
array[y] = 1;

// The line you can't do
int index = ??? GetIndex ("x");

--
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 19 '05 #5
tim
Thanks, you got it.
Is there a sort of "GetIndex" method


Array.IndexOf(yourArray, yourName)
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Sep 19 '05 #6
tim
Mattias Sjogren solved in his post.
Thanks the same

tim <ti*@inwind.it> wrote:
I have an array.

I have the name of an element.


What exactly do you mean by the "name" of the element? If you mean the
name of a variable which was used to populate the array, that has no
meaning to the object itself which is referred to by the element.

--
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 19 '05 #7
tim <ti*@inwind.it> wrote:
Mattias Sjogren solved in his post.
Thanks the same


So does that mean you were actually looking for the value itself in the
array? It's worth being very clear on this - an array element doesn't
*have* a name as such. (It may have a Name property, depending on the
type, of course.)

--
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 19 '05 #8
tim
I populated my array in this manner

Rome
then
Milan
then
Venice
then
Florence

Question:
I have Venice,
what position is it?

Now I solved .

Sep 20 '05 #9
tim <ti*@inwind.it> wrote:
I populated my array in this manner

Rome
then
Milan
then
Venice
then
Florence

Question:
I have Venice,
what position is it?

Now I solved .


Right - yes, as suspected, you have the value of the element.

--
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 20 '05 #10
Jon,

I am happy that I am not the only one who misunderstood the question.

:-)

Cor
"Jon Skeet [C# MVP]" <sk***@pobox.com> schreef in bericht
news:MP************************@msnews.microsoft.c om...
tim <ti*@inwind.it> wrote:
Mattias Sjogren solved in his post.
Thanks the same


So does that mean you were actually looking for the value itself in the
array? It's worth being very clear on this - an array element doesn't
*have* a name as such. (It may have a Name property, depending on the
type, of course.)

--
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 20 '05 #11

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

Similar topics

9
by: Acacia | last post by:
i get this error on any line with dot notation. Oh, and do I need to use cin.getline(boy.name)?: error:'.':left operand points to 'struct' use '->' This is the program in question: ...
5
by: Denis Perelyubskiy | last post by:
Hello, I need to make an array of elements accross forms. My javascript skills, as evident from this question, are rather rudimentary. I tried to make an associative array and index it with...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
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: Robert Mark Bram | last post by:
Hi All! How do you get the length of an associative array? var my_cars= new Array() my_cars="Mustang"; my_cars="Station Wagon"; my_cars="SUV"; alert(my_cars.length);
38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
11
by: motion musso aka: sathia | last post by:
this is it, how can i get the current index? couldn't figure it out. thank you for(i=0;myarray.length<i;i++){ do_something(); //i need the current myarray } bye bye
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
6
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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: 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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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

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.