存在我試圖爲int []傳遞到方法,用另一個陣列串聯,並將其返回到主控制檯打印。 這裏是代碼:INT []不在當前上下文中
//where preTemp is another array derived in previous method
public static int[] sesLayer(int[] preTemp)
{
//set two arrays for rtr and r1r0
int[] r1r0 = new int[2] { 0, 0 };
int[] RTR = new int[1] { 0 };
//add r1r0 to the preTemp int array
//set length of the new array to accomodate temp + r1r0
var length = new int[preTemp.Length + r1r0.Length];
r1r0.CopyTo(length, 0);
preTemp.CopyTo(length, length.Length);
//add RTR to the packet
return preTemp;
}
public static int[] preLayer(int tempData)
{
string binaryTemp = Convert.ToString(tempData, 2);
int DLC = binaryTemp.Length;
binaryTemp = binaryTemp.PadLeft(64, '0');
string binaryDLC = Convert.ToString(DLC, 2);
binaryDLC = binaryDLC.PadLeft(4, '0');
string prePacket = binaryDLC + binaryTemp;
//convert string to int[]
int[] preTemp = prePacket.Select(c => int.Parse(c.ToString())).ToArray();
return preTemp;
}
static void Main(string[] args)
{
int[] sesTemp = sesLayer(preTemp); //**error crops up here**
Console.Write(sesTemp);
Console.ReadLine();
}
and int tempData = 58; 任何幫助表示讚賞。
你在哪裏聲明並初始化'preTemp'? –
這就是問題,OP不是。 –
你能多解釋一下嗎? –