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 583305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:46:42+00:00 2026-05-13T14:46:42+00:00

a) Shouldn’t the following assignment cause an error, since number 100 is a literal

  • 0

a) Shouldn’t the following assignment cause an error, since number 100 is a literal of type int and since compiler doesn’t allow implicit narrowing conversions?

byte b = 100; 

b) If compiler doesn’t complain about implicit narrowing conversion from int literal to type byte, then why doesn’t it also allow an implicit narrowing conversion from double literal to type float ( I realize we could avoid this error by specifying float literal using F/f suffix )?

byte b=16; //OK
float f1=16.9; //error

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-13T14:46:42+00:00Added an answer on May 13, 2026 at 2:46 pm

    This is covered in section 6.1.8 of the C# language spec. It is legal for constant expressions of type int to be converted to sbyte, byte, short, ushort, uint or ulong provided the value is within the range of the target type. It is fairly easy for the C# compiler to determine if the value is within the appropriate range and hence allow the conversion.

    As for the double case, the C# lang spec does not specifically call out why this is not allowed. My guess is it has to do with difficulties in determining if the double value can fit within the float value. Getting floating point precision correct is a very difficult task and probably so much so it wasn’t deemed to be worth the cost (if it was possible at all)

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

Sidebar

Related Questions

Shouldn't the compiler automatically cast to a double in the following? At least according
Why is the following code prints xxY? Shouldn't local variables live in the scope
The following compiles fine in my Eclipse: final int j = 1/0; // compiles
I'm confused about COM string assignments. Which of the following string assignment is correct.
Not sure why the following doesn't work. I hope somebody can shed some light.
I was looking for some advice / help on my assignment. Since it is
What is the output of the following code: int main() { int k =
Can anyone tell me what the result to the following should be according to
I am making a game. The following should draw me a picture of c.png
The following code should show a certain track in iTunes: NSString* iTunesPath = [[NSWorkspace

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.