473,407 Members | 2,320 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,407 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 1419
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
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?
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
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...
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.