[英]How can I rewrite a python 2D vector in C#?
The following is a 2D array of vectors in Python:下面是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]];
How can I rewrite this into C#?我如何将其重写为 C#?
You can do like this:你可以这样做:
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}};
Or like this或者像这样
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}};
Microsoft article for reference: https://learn.microsoft.com/pt-br/do.net/csharp/programming-guide/arrays/multidimensional-arrays微软文章参考: https://learn.microsoft.com/pt-br/do.net/csharp/programming-guide/arrays/multidimensional-arrays
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.