From: Rick on
object[,] siblings = { { "John", 25 }, { "Mike", 30 }, { "Tom", 40 } };

Let say I have a value:
string searchString = "Mike";

How do I search for the [searchString] in the array siblings and get the age
(in case of Mike, it is 30)?
From: Jeff Johnson on
"Rick" <Rick(a)discussions.microsoft.com> wrote in message
news:E4E7F5C2-88A4-4D32-9F19-4C1DCA61B898(a)microsoft.com...

> object[,] siblings = { { "John", 25 }, { "Mike", 30 }, { "Tom", 40 } };
>
> Let say I have a value:
> string searchString = "Mike";
>
> How do I search for the [searchString] in the array siblings and get the
> age
> (in case of Mike, it is 30)?

Is your array always 2-dimensional?


From: Peter Duniho on
Rick wrote:
> object[,] siblings = { { "John", 25 }, { "Mike", 30 }, { "Tom", 40 } };
>
> Let say I have a value:
> string searchString = "Mike";
>
> How do I search for the [searchString] in the array siblings and get the age
> (in case of Mike, it is 30)?

It would be much easier if you follow Arne's earlier advice to store the
data in a single structure.

But, if you insist on the 2-dimensional array, it's as simple as
iterating over one dimension, examining the 0th element for each
iteration (which is a string) and comparing it to the string you're
looking for. Once found, the value is in the 1st element for the same
iteration index.

Pete
From: Rick on
Yes, it is always 2-dimensional.

"Jeff Johnson" wrote:

> "Rick" <Rick(a)discussions.microsoft.com> wrote in message
> news:E4E7F5C2-88A4-4D32-9F19-4C1DCA61B898(a)microsoft.com...
>
> > object[,] siblings = { { "John", 25 }, { "Mike", 30 }, { "Tom", 40 } };
> >
> > Let say I have a value:
> > string searchString = "Mike";
> >
> > How do I search for the [searchString] in the array siblings and get the
> > age
> > (in case of Mike, it is 30)?
>
> Is your array always 2-dimensional?
>
>
> .
>
From: Rick on
Would you be able to provide me with a sample code? thank you

"Peter Duniho" wrote:

> Rick wrote:
> > object[,] siblings = { { "John", 25 }, { "Mike", 30 }, { "Tom", 40 } };
> >
> > Let say I have a value:
> > string searchString = "Mike";
> >
> > How do I search for the [searchString] in the array siblings and get the age
> > (in case of Mike, it is 30)?
>
> It would be much easier if you follow Arne's earlier advice to store the
> data in a single structure.
>
> But, if you insist on the 2-dimensional array, it's as simple as
> iterating over one dimension, examining the 0th element for each
> iteration (which is a string) and comparing it to the string you're
> looking for. Once found, the value is in the 1st element for the same
> iteration index.
>
> Pete
> .
>
 |  Next  |  Last
Pages: 1 2
Prev: send basic text to webserver
Next: Where is my thread?