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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:04:10+00:00 2026-05-23T04:04:10+00:00

I created a basic console application to make such a test. short val =

  • 0

I created a basic console application to make such a test.

        short val = 32767;

        val++;

        Console.WriteLine(val);

This gives me -32768 as an expected result

        short val = 32767;

        val = val +1;

        Console.WriteLine(val);

But this gives me this error

Error 1 **Cannot implicitly convert type ‘int’ to ‘short’. An explicit conversion exists (are you missing a cast?)

I am curious about what causes this ?

Thanks in advance,

  • 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-23T04:04:11+00:00Added an answer on May 23, 2026 at 4:04 am

    The result of a short + short operation is defined as an int. In the first case, the compiler is going ahead and applying a (short) cast on the result of the increment, but it is not in the second.

    short myShort = 1;
    int resultA = myShort + myShort; // addition returns an integer
    short resultB = myShort++; // returns a short, why? 
    
    // resultB is essentially doing this
    short resultB = (short)(myShort + 1);
    

    In addition to the link provided by Joel in the comments, you can also refer to section 7.3.6.2 of the C# 4.0 language specification that lays out the rules for binary numeric promotions (covering expressions of the form a = b + c;) and also 7.6.9 that covers pre- and postfix operators.

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

Sidebar

Related Questions

I have created a basic WCF service in IIS. I am aware that this
I've created this basic 3D Demo using OpenGL/SDL. I handled the keyboard callback so
I created just the most basic WCF Service Application to do some prototyping, but
I created a basic application in Xcode 4.2. Very simple application, I have not
I've created a basic console app in Visual Studio 2008, which references an external
I created a super simple console app to test out the Enterprise Library Caching
I have a basic C# console application that I would like to run as
I have created a basic site using ASP.NET routing according to Mike Ormond's example
I have created a pretty basic Flash website for a client and am having
I created a site template from a basic site which was itself created from

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.