Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Search in an Array

0 views
Skip to first unread message

Sorin Sandu

unread,
Sep 7, 2004, 3:28:09 AM9/7/04
to
How can I find 2 values in a 2-dimensional array of int ?


Morten Wennevik

unread,
Sep 7, 2004, 3:49:05 AM9/7/04
to
Hi Sorin,

Depending on your array setup and if those two values are separate or on the same row:

int[,] n = new int[4, 5];
for (int i = 0; i <= n.GetUpperBound(0); i++)
{
for (int j = 0; j <= n.GetUpperBound(1); j++)
{
if (n[i, j] == MyInt)
DoSomething();
}
}

int[,] n = new int[5, 2];
for(int i = 0; i <= n.GetUpperBound(0); i++)
{
if(n[i,0] == MyFirstValue && n[i,1] == MySecondValue)
DoSomething();
}

--
Happy Coding!
Morten Wennevik [C# MVP]

0 new messages