First understand scenarios where we can use checked & unchecked keywords
C# compiler does not throws any error at compile or run time for arithmetic overflow.
j has assigned wrong value.
checked: Used to check arithmetic overflow, it throws arithmetic overflow exception in case of overflow.
C# compiler checks for arithmetic overflow if constant(s) involved in operation and gives compile time error.
unchecked: unchecked is used to suppress checking for arithmetic overflow by compiler
C# compiler does not throws any error at compile or run time for arithmetic overflow.
j has assigned wrong value.
checked: Used to check arithmetic overflow, it throws arithmetic overflow exception in case of overflow.
C# compiler checks for arithmetic overflow if constant(s) involved in operation and gives compile time error.
unchecked: unchecked is used to suppress checking for arithmetic overflow by compiler




No comments:
Post a Comment