有了ushort数组,ushort[]如何将ushort数组[44,55]转换为单个连接的ushort 4455?数组总是有两个元素。
ushort[] test = new ushort[2];
test[0] = 44;
test[1] = 55;
// Here I want to convert the ushort[] to a unique ushort value 4455
usortValue = ?
return usortValue;我和.join一样期待一个String函数,但是ushort是不可能的。
提前感谢
发布于 2016-05-09 08:58:46
您可以聚合,谓词是“转换为字符串、连接并解析回ushort",但迟早(快点!)会溢出。
ushort[] test = new ushort[2];
test[0] = 44;
test[1] = 55;
var result = test.Aggregate((p,c) => ushort.Parse((p.ToString() + c.ToString())));实例:http://rextester.com/VKV9570
发布于 2016-05-09 08:58:48
如何将数字转换为字符串并加入它们?
var result =string.Join("",test.Select(x=>x.ToString()));
Convert.ToUInt16(result);发布于 2016-05-09 08:58:08
ushortValue = Convert.ToUInt16(test[0].ToString() + test[1].ToString());https://stackoverflow.com/questions/37111439
复制相似问题