Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# convert from uint[] to byte[]

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;

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

like image 556
ahmd0 Avatar asked Dec 01 '22 01:12

ahmd0


1 Answers

How about:

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

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

like image 66
Matt Avatar answered Dec 04 '22 00:12

Matt