如何在 C# 中重写 python 二维向量?
How can I rewrite a python 2D vector in C#?
下面是Python中的二维向量数组:
neighbor = [[1, 3, 0, 0], [2, 4, 0, 1], [2, 5, 1, 2],
[4, 6, 3, 0], [5, 7, 3, 1], [5, 8, 4, 2],
[7, 6, 6, 3], [8, 7, 6, 4], [8, 8, 7, 5]];
如何将其重写为 C#?
你可以这样做:
int[,] neighbor = new int[,] {{1, 3, 0, 0}, {2, 4, 0, 1}, {2, 5, 1, 2},
{4, 6, 3, 0}, {5, 7, 3, 1}, {5, 8, 4, 2},
{7, 6, 6, 3}, {8, 7, 6, 4}, {8, 8, 7, 5}};
或者像这样
int[,] neighbor = {{1, 3, 0, 0}, {2, 4, 0, 1}, {2, 5, 1, 2},
{4, 6, 3, 0}, {5, 7, 3, 1}, {5, 8, 4, 2},
{7, 6, 6, 3}, {8, 7, 6, 4}, {8, 8, 7, 5}};
微软文章供参考:https://docs.microsoft.com/pt-br/dotnet/csharp/programming-guide/arrays/multidimensional-arrays
下面是Python中的二维向量数组:
neighbor = [[1, 3, 0, 0], [2, 4, 0, 1], [2, 5, 1, 2],
[4, 6, 3, 0], [5, 7, 3, 1], [5, 8, 4, 2],
[7, 6, 6, 3], [8, 7, 6, 4], [8, 8, 7, 5]];
如何将其重写为 C#?
你可以这样做:
int[,] neighbor = new int[,] {{1, 3, 0, 0}, {2, 4, 0, 1}, {2, 5, 1, 2},
{4, 6, 3, 0}, {5, 7, 3, 1}, {5, 8, 4, 2},
{7, 6, 6, 3}, {8, 7, 6, 4}, {8, 8, 7, 5}};
或者像这样
int[,] neighbor = {{1, 3, 0, 0}, {2, 4, 0, 1}, {2, 5, 1, 2},
{4, 6, 3, 0}, {5, 7, 3, 1}, {5, 8, 4, 2},
{7, 6, 6, 3}, {8, 7, 6, 4}, {8, 8, 7, 5}};
微软文章供参考:https://docs.microsoft.com/pt-br/dotnet/csharp/programming-guide/arrays/multidimensional-arrays