开发者

Correlating parallel arrays in C#

开发者 https://www.devze.com 2023-01-12 20:41 出处:网络
How can I associate two unidentical( arrays of different typ开发者_JS百科es) string arrays using C#? int lenght = 3;

How can I associate two unidentical( arrays of different typ开发者_JS百科es) string arrays using C#?


int lenght = 3;

string[] arr1 = new string [length] { "one", "two", "three", };
int[] arr2 = new int [length] { 1, 2, 3, };

string search = "two";
for (a = 0; a < lenght; a++)
{
    if (arr1[a] == search)
        Console.WriteLine("Element found at position {0}. The corresponding element is {1}", a + 1, arr2[a]);
}

I'm not sure if this is what you mean or not but you are better off using two dimensional arrays if you want rows and columns.

0

精彩评论

暂无评论...
验证码 换一张
取 消