看不懂的代码,高手来说说

凋零的老树 2016-09-12 11:29:58
public static bool Execute(string ip, int port, int sendTimeout, int receiveTimeout, string jsonSend, ref string jsonRec, byte mti1, byte mti2)
{
for (int i = 0; i < 1; i++)
{
TcpClient client = null;
try
{
int num2 = 0x100000;
byte[] bytes = Encoding.UTF8.GetBytes(jsonSend);

client = new TcpClient {
SendBufferSize = num2,
ReceiveBufferSize = num2
};
client.Connect(ip, Convert.ToInt32(port));
using (NetworkStream stream = client.GetStream())
{
byte[] buffer3;
bool flag2;
stream.WriteTimeout = sendTimeout;
stream.ReadTimeout = receiveTimeout;
stream.Write(bytes, 0, bytes.Length);
bytes = null;
int length = 0;
goto Label_010A;
Label_0092:
buffer3 = new byte[num2];
int num4 = stream.Read(buffer3, 0, buffer3.Length);
byte[] destinationArray = new byte[num4];
Array.Copy(buffer3, destinationArray, num4);
bytes = ConverterUtil.CombinByteArray(bytes, destinationArray);
byte[] buffer5 =bytes;
if (buffer5 != null)
{
buffer5 = ConverterUtil.DecodingMessageHeader(buffer5);
length = ConverterUtil.ByteArrayToInt(buffer5, 4);
if (bytes.Length >= (length + buffer5.Length))
{
goto Label_010F;
}
}
Label_010A:
flag2 = true;
goto Label_0092;
Label_010F:
if (bytes != null)
{
byte[] buffer6 = new byte[length];
Array.Copy(bytes, bytes.Length - length, buffer6, 0, length);
jsonRec = Encoding.UTF8.GetString(buffer6);
}
return true;
}
}
catch (Exception exception)
{

Thread.Sleep(0x3e8);
}
finally
{
try
{
client.Close();
}
catch
{
}
}
}
return false;
}
有两个疑问:
1.为什么要用goto,
2.为什么 for (int i = 0; i < 1; i++) 这个0到1有什么意义啊?
...全文
390 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
凋零的老树 2016-09-13
  • 打赏
  • 举报
回复
这个代码确实我反编译过来的
gettable 2016-09-12
  • 打赏
  • 举报
回复
很明显这段代码是通过Reflector工具反编译来的,这些代码你需要进行加工处理,你可以将类似“Label_010F:”下面的代码复制替换“goto Label_010F;”
Forty2 2016-09-12
  • 打赏
  • 举报
回复
引用 楼主 kongxiangli 的回复:
有两个疑问:
因为那是机器写的(或者说机器反编译中间代码)。
凋零的老树 2016-09-12
  • 打赏
  • 举报
回复
还有 TcpClient 有标准写法没?
sqxinquan 2016-09-12
  • 打赏
  • 举报
回复
go to指针现在很少用了吧,只有在C语言中用的多一些。
秋的红果实 2016-09-12
  • 打赏
  • 举报
回复
C#一般不用goto,容易造成混乱。 这个估计是从IL反向而来 for语句体内没有用到I,说明只是用来控制执行次数(只执行1次)的
ok-go 2016-09-12
  • 打赏
  • 举报
回复
goto 这东西很少用吧, 记得 以前刚搞VB的时候用过, 没想到C#也有,不过 很少会用到的

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧