How to Create a byte array from stream in C#?

By 3rd June 2019C#
Moslty we want to save images or any file in database as byte, so we can convert any stream in byte array in c#, here below a method to convert.

 public static byte[] StreamToBytes(Stream input)
        {
            byte[] buffer = new byte[16 * 1024];
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }