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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:41:42+00:00 2026-05-31T18:41:42+00:00

One of my data types in SqlServer is smallint and this maps to short

  • 0

One of my data types in SqlServer is smallint and this maps to short or Int16 in .NET. I was using a simple for loop with i being an int and it told me it couldn’t implicitly convert between the two?

I was just wondering why this isn’t possible? Is it just to prevent you from using a larger number than a short can hold? It seems strange to me because I’m around 80% sure I’ve never had to convert an int to a long?

Sample:

public Int16 Test()
{
    int i = 2;
    return i;
}
  • 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-31T18:41:44+00:00Added an answer on May 31, 2026 at 6:41 pm

    An implicit from short to int should exist because you are going from narrow to wide, wide to narrow is not supported implicitly because of potential data loss. The compiler allows you to ignore this, but requests that you cast explicitly in these cases to state that you’ve understood the potential and that you are OK with it.

    Update:

    Your code is a narrowing cast and cannot be done implicitly. Fix:

    public Int16 Test()
    {
        int i = 2;
        return (Int16)i;
    }
    

    Although, to be facetious, in this particular case the compiler could theoretically know that no data loss will occur. For the other 99.99% of the time it cannot know this at compile time, thus only explicit casting is supported where data loss might occur.

    This clearly places the onus on the developer such that when a runtime error occurs due to data loss, the developer would have had to consciously make that decision prior and has no legal standing to hurl expletives at the computer.

    VB.NET appears to allow you to circumvent even this restriction using Option Strict:

    http://msdn.microsoft.com/en-us/library/k1e94s7e(v=vs.80).aspx

    So I presume this is a C# specific design choice.

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

Sidebar

Related Questions

I need to copy data from one database to another using a VB.NET program.
SQL Server 2008 has new geo data types. One thing I am wondering though
I had a bunch of bookmark to www.asp.net/learn/, specially the one about data-access and
I am pulling data from one table, called analyzedCopy, and using it to over-rite
I am having this big database on one MSSQL server that contains data indexed
I implemented one service and it has several configuration item, such as data type,
I am starting to migrate a custom serialization mechanism to Protocol Buffers. One data
One of the data structures in my current project requires that I store lists
How does one read a data file in an iPhone project? For example, lets
I want to port data from one server's database to another server's database. The

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.