问题描述
int [] array;
int [,] population;
for (i=0;i<columns,i++)
{
for(j=0;j<rows;j++)>
{
population[i, j] = array;
}
}
错误无法将类型int []转换为int
出错了什么
the error is unable to convert type int [] to int
what is wrong
推荐答案
错误无法将类型int []转换为int
出了什么问题
the error is unable to convert type int [] to int
what is wrong
你的方法错了:一个数组项(比如 population [i,j]
)是一个标量类型(即你的情况下是一个数字),而整个数组(如数组
)是标量类型的集合(是数组
包含多个数字)。你不能将一个集合分配给一个号码。
以下行
Your approach is wrong: an array item (like population[i,j]
) is a scalar type (i.e. a single number in your case) while a whole array (like array
) is a collection of scalar types (that is array
contains many numbers). You cannot assign a collection to a single number.
The following line
population[i, j] = array[j];
在语法上是正确的(但它可能在语义错误,它可能会产生运行时错误,等等...)。
[更新]
你做不到对于二维数组,你必须使用锯齿状数组,例如:
[]
[/ Update]
for(int i = 0;i<10;i++)
{
for(int j = 0; j< 20; j++)
{
Population[i][j] = array[i];
}
}
意味着:嘿编译器取位于数组并索引i放入索引i和j的填充。
it means : hey compiler take the located at array and index i an put that in population at index i and j.
int array;
int Population[10][20];
for(int i = 0;i<10;i++)
{
for(int j = 0; j< 20; j++)
{
Population[i][j] = array;
}
}
这篇关于无法将int []类型转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!