Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 874467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:06:28+00:00 2026-05-15T11:06:28+00:00

1) Is UNCHECKED operator in effect only when expression inside UNCHECKED context uses an

  • 0

1) Is UNCHECKED operator in effect only when expression inside UNCHECKED context uses an explicit cast ( such as byte b1=unchecked((byte)2000); ) and when conversion to particular type can happen implicitly? I’m assuming this since the following expression throws a compile time error:

byte b1=unchecked(2000); //compile time error

2) a) Do CHECKED and UNCHECKED operators work only when resulting value of an expression or conversion is of an integer type? I’m assuming this since in the first example ( where double type is being converted to integer type ) CHECKED operator works as expected:

        double m = double.MaxValue;
        b=checked((byte)m); // reports an exception

, while in second example ( where double type is being converted to a float type ) CHECKED operator doesn’t seem to be working. since it doesn’t throw an exception:

        double m = double.MaxValue;
        float f = checked((float)m); // no exception thrown

b) Why don’t the two operators also work with expressions where type of a resulting value is of floating-point type?

2) Next quote is from Microsoft’s site:

The unchecked keyword is used to control the overflow-checking context for integral-type arithmetic operations and conversions

I’m not sure I understand what exactly have expressions and conversions such as unchecked((byte)(100+200)); in common with integrals?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:06:29+00:00Added an answer on May 15, 2026 at 11:06 am

    Is unchecked operator in effect only when expression inside unchecked context uses an explicit cast and when conversion to particular type can happen implicitly?

    No. All operations inside the unchecked operator are unchecked, unless of course the unchecked operator then contains a checked operator.

    Do checked and unchecked operators work only when resulting value of an expression or conversion is of an integer type?

    The checked and unchecked operators only have an observable effect on integral types, yes.

    Why don’t the two operators also work with expressions where type of a resulting value is of floating-point type?

    Double and float types have infinity, negative infinity and NaN values that can be used as the result of an overflowing operation. There are no “unassigned” values in any integral type that are reserved for “error” situations like this. Double and float can signal the error condition through their values; integers cannot. Therefore you need to be able to turn on some signalling mechanism for integer errors if you want to detect overflows.

    The unchecked keyword is used to control the overflow-checking context for integral-type arithmetic operations and conversions

    Correct. I note that this answers your first two questions.

    I’m not sure I understand what exactly have expressions and conversions such as unchecked((byte)(100+200)); in common with integrals?

    100 is of integral type. 200 is of integral type. Their sum is of integral type. And byte is an integral type. Everything in that expression is of integral type.

    Thank you

    You’re welcome.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got the unchecked expression error when compiling and found the offending line to
I think I get what unchecked cast means (casting from one to another of
Eclipse is giving me a warning of the following form: Type safety: Unchecked cast
I'm getting a Type safety: Unchecked cast from Object to ArrayList warning on the
I want read-only check boxes to be greyed out, but display their checked/unchecked status
byte b; int i; unchecked { b = 255 + 255; //overflows i =
For example: javac Foo.java Note: Foo.java uses unchecked or unsafe operations. Note: Recompile with
As I'm tired of writing a cast operator for EVERY Activity.findViewById() that returns raw
Just noticed that the unchecked context doesn't work when working with a BigInteger, for
int int1; byte byte1; unchecked { int1 = 2147483647 + 10; //ok byte1 =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.