Learn c#
  • Overview
  • Chapter 0 c# vs .net
  • Chapter 1 Definitions
    • Data Types (Primitive Types)
    • Variables
    • Overflow
    • Identifiers
    • Comments
  • Chapter 2 Type Conversions
  • Chapter 3 C# Operators
  • Chapter 4 Non-Primitive Types
    • Reference Types and value types
    • Class, Fields, property
    • Structs and Arrays
    • Strings
    • Enums
  • Chapter 5 Conditional statements and Loops
    • Conditional Statements
    • Random Class
  • External Links
    • cSharp-Station
    • cSharp corner
    • CodeProject
    • cSharp Guide by Microsoft
  • Tips
Powered by GitBook
On this page
  1. Chapter 1 Definitions

Overflow

Lets say you assign value 255 to a byte data type. If you increment that value and try to get that value, it would show zero, because, the biggest value that a byte can take is, 255. If you increment it more, it would go beyond 255 and it doesnt know how to handle it. This is called overflowing.

Ex: byte number = 255;

number = number + 1;

This would result a zero value. Either use keyword “checked” or change data type of number to int or something else.

checked

{

byte number = 2;

number = number +1;

}

PreviousVariablesNextIdentifiers

Last updated 6 years ago