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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:32:46+00:00 2026-06-11T12:32:46+00:00

From the C# Type Conversion Tables(http://msdn.microsoft.com/en-us/library/08h86h00.aspx): A narrowing conversion can also result in a

  • 0

From the C# Type Conversion Tables(http://msdn.microsoft.com/en-us/library/08h86h00.aspx): “A narrowing conversion can also result in a loss of information for other data types. However, an OverflowException is thrown if the value of a type that is being converted falls outside of the range specified by the target type’s MaxValue and MinValue fields, and the conversion is checked by the runtime to ensure that the value of the target type does not exceed its MaxValue or MinValue.”

So I was expecting the following code to generate an exception:

static void Main() {
    int numb1 = 333333333;
    short numb2 = (short)numb1;

    Console.WriteLine("Value of numb1 is {0}", numb1);
    Console.WriteLine("Type of numb1 is {0}", numb1.GetType());
    Console.WriteLine("MinValue of int is {0}", int.MinValue);
    Console.WriteLine("MaxValue of int is {0}\n", int.MaxValue);

    Console.WriteLine("Value of numb2 is {0}", numb2);
    Console.WriteLine("Type of numb2 is {0}", numb2.GetType());
    Console.WriteLine("MinValue of short is {0}", short.MinValue);
    Console.WriteLine("MaxValue of short is {0}", short.MaxValue);

    Console.ReadKey();
}

but instead numb2 gets a value of 17237. I don’t know where this value comes from and I really don’t understand why an overflow exception wasn’t generated.

Any suggestion is highly appreciated! Thanks.

  • 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-06-11T12:32:48+00:00Added an answer on June 11, 2026 at 12:32 pm

    Numeric conversions are not checked by default. You can force this by using a checked block:

    checked { short s = (short)numb1; }
    

    Alternatively you can use the Convert class which does check conversions:

    short s = Convert.ToInt16(numb1);
    

    There’s also a checked compiler option

    The value 17237 is simply the lower 16 bits of 333333333 (i.e. 333333333 truncated to fit in a short):

    int s = numb1 & 0x0000FFFF;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an implicit conversion from any type (say, Int) to
I'm getting this warning from sccanf() : ../../../../ext/oedipus/oedipus.c:211: warning: conversion lacks type at end
I'm getting a compile error conversion from 'int*' to non-scalar type 'foo< int>' requested
I mean I can't type from my laptop keyboard into android emulator anymore. Virtual
I need to convert keys from type string to hash. The name of all
I get this error about casting from type A to type B because the
I have an oracle table with a column from type SYS.XMLTYPE and a storage
Which Activator.CreateInstance overload function to call? I have a type returned from Type proxyType
I have queue from struct type struct test { int numbers; }; queue<test> q;
The method showDialog(int) from the type Activity is deprecated . What's the reason? and

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.