+ 1
Why is this outputting 0 instead of throwing an error
byte b = 255; b += 1; Console.Write(b); // 0 Any answer is appreciated.
11 Antworten
+ 5
Nick error is only thrown in checked context , otherwise it truncates the higher order bits as this article says,
https://docs.microsoft.com/en-us/dotnet/api/system.overflowexception?view=net-5.0
+ 2
https://code.sololearn.com/ck3yC93hsWIA/?ref=app
+ 2
Rushikesh
byte in C# is an unsigned value
+ 2
Rushikesh
I appreciate the answers that you've given, but this thread has nothing to do with Java if you take a look at the tag.
+ 1
In c#
sbyte - -128 to 127
Byte 0-255
+ 1
Rushikesh
But can you explain why the integer didn't overflow
0
Nick iam talking about java
for just to know about byte size
0
That means your adding one to 255(heighest byte value)
Which is not possible
0
Byte can only have max 255. sbyte can have -128-128. Use int or long.
- 1
Byte highest value is just 127 to -128🤔
but it can go to 255
266 is out of range according to file sizes
- 1
C# does not check overflow exceptions
like any other languages