Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我需要从C中的2d数组中获取行和列的值#_C#_.net_Arrays_Linq - Fatal编程技术网

C# 我需要从C中的2d数组中获取行和列的值#

C# 我需要从C中的2d数组中获取行和列的值#,c#,.net,arrays,linq,C#,.net,Arrays,Linq,我完全被难住了。我已经在50x50二维数组中的随机位置插入了字符串,我需要通过字符串过滤数组,找到它的索引,并以某种方式从该索引中获取行/列(或x,y坐标)。 我用的是C#。我觉得没有必要解释更大的程序,因为这是我唯一的问题 我应该使用列表吗?我无法在2d数组上使用indexOf方法,因此该方法不起作用。参考: 希望它有帮助如果你想要一个简单的二次时间算法,用双嵌套for循环遍历2D数组的每个元素,并进行字符串比较,然后返回(x,y)值(如果找到)。检查我下面的答案。我很感激!我现在就去看看。

我完全被难住了。我已经在50x50二维数组中的随机位置插入了字符串,我需要通过字符串过滤数组,找到它的索引,并以某种方式从该索引中获取行/列(或x,y坐标)。 我用的是C#。我觉得没有必要解释更大的程序,因为这是我唯一的问题

我应该使用列表吗?我无法在2d数组上使用indexOf方法,因此该方法不起作用。

参考:


希望它有帮助

如果你想要一个简单的二次时间算法,用双嵌套for循环遍历2D数组的每个元素,并进行字符串比较,然后返回(x,y)值(如果找到)。检查我下面的答案。我很感激!我现在就去看看。
using System;
    namespace ArrayApplication
    {
       class MyArray
       {
          static void Main(string[] args)
          {
             /* an array with 5 rows and 2 columns*/
             int[,] a = new int[5, 2] {{0,0}, {1,2}, {2,4}, {3,6}, {4,8} };
             int i, j;

             /* output each array element's value */
             for (i = 0; i < 5; i++)
             {
                for (j = 0; j < 2; j++)
                {
                   Console.WriteLine("a[{0},{1}] = {2}", i, j, a[i,j]);
                }
             }
             Console.ReadKey();
          }
       }
    }
    a[0,0]: 0
    a[0,1]: 0
    a[1,0]: 1
    a[1,1]: 2
    a[2,0]: 2
    a[2,1]: 4
    a[3,0]: 3
    a[3,1]: 6
    a[4,0]: 4
    a[4,1]: 8