int[] convert byte[]

private void button_Click(object sender, RoutedEventArgs e)
        {
            byte[] bytes = this.ConvertIntArrayToByteArray(this.GetIntArray());

            int byteCount = bytes.Length;

            Console.WriteLine(byteCount.ToString());
        }

        private int[] GetIntArray()
        {
            return new int[5] { 1, 2, 3, 4, 5 };
        }

        private byte[] ConvertIntArrayToByteArray(int[] intArray)
        {
            List<byte> lst = new List<byte>();

            foreach (int item in intArray)
            {
                byte[] bytes = BitConverter.GetBytes(item);

                if(bytes != null)
                    lst.AddRange(bytes);
            }

            return lst.ToArray();
        }
原文地址:https://www.cnblogs.com/zhangchenliang/p/6020516.html