自己写的一段代码,
编译,出现:1、使用了未赋值的局部变量“array1、array2,array3";2、使用了未赋值的局部变量“s1、s2、s3”
代码如下:
class Program
{
static void Main(string[] args)
{
int s1,s2,s3,s4 = 0;
int[] array1,array2,array3,array4=new int[80];
for (int m = 0; m < 81; m++)
{
Utility uty = new Utility();
int n1,n2,n3,n4 = 0;
n1 = m % 3;
uty.CreateList(array1,m,n1,ref s1);
n2 = (m / 3) % 3;
uty.CreateList(array2,m,n2,ref s2);
n3 = ((m / 3) / 3) % 3;
uty.CreateList(array3,m,n3,ref s3);
n4 = (((m / 3) / 3) / 3) % 3;
uty.CreateList(array4,m,n4,ref s4);
}
}
}
public class Utility
{
public Utility()
{
} public void CreateList(int[] array,int m,int n,ref int s) //suffix下标
{
if ( n> 0)
{
int i = 0;
while (i < n)
{
array[s++] = m;
}
}
}
}
请高手指点……
编译,出现:1、使用了未赋值的局部变量“array1、array2,array3";2、使用了未赋值的局部变量“s1、s2、s3”
代码如下:
class Program
{
static void Main(string[] args)
{
int s1,s2,s3,s4 = 0;
int[] array1,array2,array3,array4=new int[80];
for (int m = 0; m < 81; m++)
{
Utility uty = new Utility();
int n1,n2,n3,n4 = 0;
n1 = m % 3;
uty.CreateList(array1,m,n1,ref s1);
n2 = (m / 3) % 3;
uty.CreateList(array2,m,n2,ref s2);
n3 = ((m / 3) / 3) % 3;
uty.CreateList(array3,m,n3,ref s3);
n4 = (((m / 3) / 3) / 3) % 3;
uty.CreateList(array4,m,n4,ref s4);
}
}
}
public class Utility
{
public Utility()
{
} public void CreateList(int[] array,int m,int n,ref int s) //suffix下标
{
if ( n> 0)
{
int i = 0;
while (i < n)
{
array[s++] = m;
}
}
}
}
请高手指点……
int[] array1,array2,array3,array4=new int[80];
s1,s2,s3都没赋值。后面的都一样。如果你是想要这种效果。可以不甩编译器。只是警告而已,