我有一个任务要在NodeJs中重写C#代码。不幸的是,在该功能中有一些令人讨厌的一体机,我不完全了解。
码
int b, sign = ((b = byteBuffer.ReadByte()) >> 6) & 1, i = b & 0x3F, offset = 6;
题
我可以看到有多个分配,但是我不确定这些变量应该具有什么值。
有人可以解释这个oneliner和/或将其重写为更简单的C#代码段吗?
基本上和
int b = byteBuffer.ReadByte();
int sign = (b >> 6) & 1;
int i = b & 0x3F;
int offset = 6;
详细地:
在原始行中,每个顶级都,
拆分声明:
int b, sign = ((b = byteBuffer.ReadByte()) >> 6) & 1, i = b & 0x3F, offset = 6;
^here ^here ^ here
然后您会遇到一个棘手的问题:
int b;
int sign = ((b = byteBuffer.ReadByte()) >> 6) & 1;
// ...
实际上,它首先将B定义为没有初始值,然后下一个表达式立即将'ReadByte'的结果分配给B作为第一个子操作,因此实际上与从头开始用B初始化B相同,并且您最终得到了我在第一个代码段中写的内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句