在控制台上限制2D数组大小(C#)
这是我的密码在控制台上限制2D数组大小(C#),c#,android,unity3d,C#,Android,Unity3d,这是我的密码 public int[,] GetBigEyeRoad(int x) { int[,] arrayBigEyeResult = new int[6, x]; Array.Copy(arrayBigEyeRoad, arrayBigEyeResult, arrayBigEyeRoad.GetLength(0) * arrayBigEyeRoad.GetLength(1)); return arrayBigEyeResult; } 像这样在我的主课上打电话 in
public int[,] GetBigEyeRoad(int x)
{
int[,] arrayBigEyeResult = new int[6, x];
Array.Copy(arrayBigEyeRoad, arrayBigEyeResult, arrayBigEyeRoad.GetLength(0) * arrayBigEyeRoad.GetLength(1));
return arrayBigEyeResult;
}
像这样在我的主课上打电话
int[,] arrayBigEyeRoad = bsb.GetBigEyeRoad(104);
string s = "";
for (int y = 0; y < arrayBigEyeRoad.GetLength(0); y++)
{
for (int x = 0; x < arrayBigEyeRoad.GetLength(1); x++)
{
s += string.Format("{0:D2}", arrayBigEyeRoad[y, x]);
s += ".";
}
s += "\n";
}
Debug.Log(s);
int[,] arrayBigEyeRoad = bsb.GetBigEyeRoad(12);
我只想像这样显示12
2D数组值
int[,] arrayBigEyeRoad = bsb.GetBigEyeRoad(104);
string s = "";
for (int y = 0; y < arrayBigEyeRoad.GetLength(0); y++)
{
for (int x = 0; x < arrayBigEyeRoad.GetLength(1); x++)
{
s += string.Format("{0:D2}", arrayBigEyeRoad[y, x]);
s += ".";
}
s += "\n";
}
Debug.Log(s);
int[,] arrayBigEyeRoad = bsb.GetBigEyeRoad(12);
问题是它不让我这么做。因为它会给我一个错误的说法
目标数组不够长。检查destIndex和length,以及数组的下限
现在我怎么可能做到这样呢
int[,] arrayBigEyeRoad = bsb.GetBigEyeRoad(104);
string s = "";
for (int y = 0; y < arrayBigEyeRoad.GetLength(0); y++)
{
for (int x = 0; x < arrayBigEyeRoad.GetLength(1); x++)
{
s += string.Format("{0:D2}", arrayBigEyeRoad[y, x]);
s += ".";
}
s += "\n";
}
Debug.Log(s);
int[,] arrayBigEyeRoad = bsb.GetBigEyeRoad(12);
限制控制台上的2d显示非常简单:
int[,] a1 = new int[100,200];
int[,] a2 = new int[10,5];
for (int i = 0; i < 10; i++)
for (int j = 0; j < 5; j++)
a2[i,j] = a1[i,j];
int[,]a1=新的int[100200];
int[,]a2=新的int[10,5];
对于(int i=0;i<10;i++)
对于(int j=0;j<5;j++)
a2[i,j]=a1[i,j];
或
公共类MyArray:int[,]
{
公共重写字符串ToString()
{
字符串结果=”;
对于(int i=0;i<10;i++)
对于(int j=0;j<5;j++)
结果+=(a1[i,j].ToString()+“,”);
返回结果;
}
}
非常简单:
int[,] a1 = new int[100,200];
int[,] a2 = new int[10,5];
for (int i = 0; i < 10; i++)
for (int j = 0; j < 5; j++)
a2[i,j] = a1[i,j];
int[,]a1=新的int[100200];
int[,]a2=新的int[10,5];
对于(int i=0;i<10;i++)
对于(int j=0;j<5;j++)
a2[i,j]=a1[i,j];
或
公共类MyArray:int[,]
{
公共重写字符串ToString()
{
字符串结果=”;
对于(int i=0;i<10;i++)
对于(int j=0;j<5;j++)
结果+=(a1[i,j].ToString()+“,”);
返回结果;
}
}
为什么不将项目从一个数组逐个复制到另一个数组?而不是数组。Copy@Bijan一个接一个?我该怎么做?为什么不把项目从一个数组一个一个地复制到另一个数组?而不是数组。Copy@Bijan一个接一个?我该怎么做呢?所以我不能复制a1中的所有元素??正如你在上图中看到的那样,我是否可以隐藏这些值,或者我真的应该这样做?你也可以覆盖到字符串谢谢你所以我不能复制a1中的所有元素??正如你在上图中看到的那样,我有可能是否可以隐藏这些值,或者这真的是我应该做的吗?您也可以覆盖ToString非常感谢您