Ich versuche, ein int [] in die Methode zu übergeben, verkette es mit einem anderen Array und gebe es an main zurück, um in der Konsole zu drucken. Hier ist der Code:int [] existiert nicht im aktuellen Kontext
//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();
}
und die int TempData = 58; Jede Hilfe wird geschätzt.
wo deklarieren und initialisieren Sie 'preTemp'? –
Das ist das Problem, das OP ist nicht. –
Können Sie etwas mehr erklären? –