Click here to Skip to main content
15,879,535 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Irked! Irked I am. Pin
Peter_in_278017-Aug-23 14:59
professionalPeter_in_278017-Aug-23 14:59 
GeneralRe: Irked! Irked I am. Pin
BernardIE531717-Aug-23 15:41
BernardIE531717-Aug-23 15:41 
GeneralRe: Irked! Irked I am. Pin
PIEBALDconsult17-Aug-23 15:40
mvePIEBALDconsult17-Aug-23 15:40 
GeneralRe: Irked! Irked I am. Pin
Graeme_Grant17-Aug-23 16:18
mvaGraeme_Grant17-Aug-23 16:18 
GeneralRe: Irked! Irked I am. Pin
PIEBALDconsult17-Aug-23 16:31
mvePIEBALDconsult17-Aug-23 16:31 
GeneralRe: Irked! Irked I am. Pin
Graeme_Grant17-Aug-23 16:49
mvaGraeme_Grant17-Aug-23 16:49 
GeneralRe: Irked! Irked I am. Pin
Daniel Pfeffer17-Aug-23 17:41
professionalDaniel Pfeffer17-Aug-23 17:41 
GeneralRe: Irked! Irked I am. Pin
Richard Deeming17-Aug-23 21:33
mveRichard Deeming17-Aug-23 21:33 
PIEBALDconsult wrote:
I would much rather have FileStream.ReadByte() throw an Exception when it hits EOF.
Using exceptions for non-exceptional, totally expected situations, just to control program flow. Dead | X|

If you really need to read a single byte at a time, then a TryReadByte method would be preferable:
C#
public static bool TryReadByte(this Stream stream, out byte value)
{
    int result = stream.ReadByte();
    if (result == -1)
    {
        value = default;
        return false;
    }
    
    value = (byte)result;
    return true;
}

Otherwise, use Read(byte[], int, int) or Read(Span<byte>) and check how many bytes were read.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Irked! Irked I am. Pin
Jörgen Andersson17-Aug-23 21:40
professionalJörgen Andersson17-Aug-23 21:40 
GeneralRe: Irked! Irked I am. Pin
PIEBALDconsult18-Aug-23 4:13
mvePIEBALDconsult18-Aug-23 4:13 
GeneralRe: Irked! Irked I am. Pin
Jörgen Andersson18-Aug-23 4:35
professionalJörgen Andersson18-Aug-23 4:35 
GeneralRe: Irked! Irked I am. Pin
PIEBALDconsult18-Aug-23 5:52
mvePIEBALDconsult18-Aug-23 5:52 
GeneralRe: Irked! Irked I am. Pin
jschell18-Aug-23 12:15
jschell18-Aug-23 12:15 
GeneralRe: Irked! Irked I am. Pin
PIEBALDconsult18-Aug-23 12:51
mvePIEBALDconsult18-Aug-23 12:51 
GeneralFound a new way to get rid of scammers. Pin
OriginalGriff17-Aug-23 8:47
mveOriginalGriff17-Aug-23 8:47 
GeneralRe: Found a new way to get rid of scammers. Pin
Slacker00717-Aug-23 8:58
professionalSlacker00717-Aug-23 8:58 
GeneralRe: Found a new way to get rid of scammers. Pin
raddevus17-Aug-23 9:52
mvaraddevus17-Aug-23 9:52 
GeneralRe: Found a new way to get rid of scammers. Pin
pkfox17-Aug-23 22:14
professionalpkfox17-Aug-23 22:14 
GeneralRe: Found a new way to get rid of scammers. Pin
MarkTJohnson17-Aug-23 10:02
professionalMarkTJohnson17-Aug-23 10:02 
GeneralRe: Found a new way to get rid of scammers. Pin
dandy7217-Aug-23 10:43
dandy7217-Aug-23 10:43 
GeneralRe: Found a new way to get rid of scammers. Pin
Graeme_Grant17-Aug-23 15:57
mvaGraeme_Grant17-Aug-23 15:57 
GeneralRe: Found a new way to get rid of scammers. Pin
Richard Deeming17-Aug-23 21:36
mveRichard Deeming17-Aug-23 21:36 
GeneralRe: Found a new way to get rid of scammers. Pin
Richard MacCutchan17-Aug-23 21:43
mveRichard MacCutchan17-Aug-23 21:43 
GeneralRe: Found a new way to get rid of scammers. Pin
obermd18-Aug-23 3:44
obermd18-Aug-23 3:44 
GeneralRe: Found a new way to get rid of scammers. Pin
jschell18-Aug-23 12:17
jschell18-Aug-23 12:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.