C#从UINT []转换为byte [] [英] C# convert from uint[] to byte[]

查看:472
本文介绍了C#从UINT []转换为byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个简单的,但我似乎无法找到一个简单的方法来做到这一点。我需要的84 UINT的数组保存到一个SQL数据库的BINARY字段。所以我用下面的线在我的C#ASP.NET项目:

This might be a simple one, but I can't seem to find an easy way to do it. I need to save an array of 84 uint's into an SQL database's BINARY field. So I'm using the following lines in my C# ASP.NET project:

//This is what I have
uint[] uintArray;

//I need to convert from uint[] to byte[]
byte[] byteArray = ???

cmd.Parameters.Add("@myBindaryData", SqlDbType.Binary).Value = byteArray;



那么,如何从UINT []转换为byte []?

So how do you convert from uint[] to byte[]?

推荐答案

如何:

byte[] byteArray = uintArray.SelectMany(BitConverter.GetBytes).ToArray();

这会做你想要什么,在小尾数格式...

This'll do what you want, in little-endian format...

这篇关于C#从UINT []转换为byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆