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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:25:39+00:00 2026-06-11T06:25:39+00:00

Why var a = 7; would set a type to a certain type (i.e.

  • 0

Why var a = 7; would set a type to a certain type (i.e. int instead of byte)? Are there any rules/defaults/checks made on the fly by C# compiler?

  • 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-11T06:25:40+00:00Added an answer on June 11, 2026 at 6:25 am

    It’s not clear what you mean by “on the fly” – but the C# compiler simply follows the rules laid down in the spec. For a declaration of the kind:

    var a = expression;
    

    the type of a is the type of expression. The expression 7 is of type int, although it’s also known to be a constant within the range of byte, allowing:

    byte a = 7;
    

    to compile. The availability of that conversion to byte doesn’t change the type of the expression 7 though, so int is what the C# compiler uses for the type of a.

    Note that I’d recommend against using var for constants like this. It ends up with code which can get pretty confusing around the boundaries of int, uint, long etc. var is meant to help with anonymous types, and also to help make code more readable. When it makes code less readable, just don’t use it.

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

Sidebar

Related Questions

I have a set of tabs which cause certain DIVs with options to 'fly
I would like to set a variable in bash called test_var Basically, I want
I would like to define the following in Javascript: var tileXml = new Array();
It would be exceedingly handy if I could do this: var MyObject = function(param1,
I would expect a Dictionary object of the form: var dict = new Dictionary<string,string>()
How would I go about doing this: for( var i = 0; i <
For example var string = 'width=300 height=650' i would like to update height in
I would like to UCASE or ToUpper a column in my LINQ query. var
How would I achieve something along the lines of this.. var Persistence = new
How would I apply the off directive to a named handler? ex var $btn

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.