C# Stream to byte[]

Date: 2021-07-22
public class StreamHelper
{
	public static byte[] ToByteArray(Stream input)
	{
		if (input is MemoryStream stream)
			return stream.ToArray();

		using (var ms = new MemoryStream())
		{
			input.Position = 0;
			input.CopyTo(ms);
			return ms.ToArray();
		}
	}
}
51880cookie-checkC# Stream to byte[]