Пустой List - C#
Формулировка задачи:
почему тут постоянно пустой лист
byte[] masCount = new byte[4];
TcpListener lis = new TcpListener(8840);
lis.Start();
var cl = lis.AcceptTcpClient();
Console.WriteLine("connect");
cl.GetStream().Read(masCount, 0, masCount.Length);
int fourByte = BitConverter.ToInt32(masCount, 0);
Console.WriteLine(fourByte);
byte[] readFourByte = new byte[4];
List<byte> input = new List<byte>();
int i = 0;
while (i < fourByte)
{
cl.GetStream().Read(readFourByte, 0, readFourByte.Length);
//Console.WriteLine(Encoding.UTF8.GetString(readFourByte));
input.AddRange(Encoding.Default.GetBytes(Encoding.UTF8.GetString(readFourByte)));
i++;
}
Console.WriteLine(Encoding.UTF8.GetString(input.ToArray()));Решение задачи: «Пустой List»
textual
Листинг программы
List<byte> input = new List<byte>();
byte[] readFourByte = new byte[4];
for (int j = 0; j < RealByteLenght;)
{
var realBytes = cl.GetStream().Read(readFourByte, 0, readFourByte.Length);
for (int bi = 0; bi < realBytes; bi++)
{
input.Add(readFourByte[bi]);
}
if (realBytes == 0)
{
break;
}
//Console.WriteLine(Encoding.UTF8.GetString(readFourByte));
j += realBytes;
}