System.IO.BinaryReader.ReadByte C# (CSharp) Method

ReadByte() public method

public ReadByte ( ) : byte
return byte
        public virtual byte ReadByte()
        {
            // Inlined to avoid some method call overhead with FillBuffer.
            if (_stream == null)
            {
                throw new ObjectDisposedException(null, SR.ObjectDisposed_FileClosed);
            }

            int b = _stream.ReadByte();
            if (b == -1)
            {
                throw new EndOfStreamException(SR.IO_EOF_ReadBeyondEOF);
            }

            return (byte)b;
        }

Usage Example

Example #1
0
        public static bool IsIMGAllowedExtension(Stream stream)
        {
            System.IO.BinaryReader r = new System.IO.BinaryReader(stream);
            string fileclass         = "";
            byte   buffer;

            try
            {
                buffer     = r.ReadByte();
                fileclass  = buffer.ToString();
                buffer     = r.ReadByte();
                fileclass += buffer.ToString();
            }
            catch
            {
            }
            r.Close();
            if (fileclass == "255216" || fileclass == "7173" || fileclass == "6677" || fileclass == "13780")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
All Usage Examples Of System.IO.BinaryReader::ReadByte