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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:11:42+00:00 2026-05-22T17:11:42+00:00

this: const int a = 5; compiles just fine, whereas const var a =

  • 0

this:

const int a = 5;

compiles just fine, whereas

const var a = 5;

doesn’t… while:

var a = 5;

compiles just as well as this:

int a = 5;

why?

  • 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-22T17:11:43+00:00Added an answer on May 22, 2026 at 5:11 pm

    The var keyword was intended to save you from writing long complex typenames, which cannot be constants.

    It is very convenient to be able to write declarations like

    var dict = new Dictionary<string, List<Definition>>();
    

    It becomes necessary when using anonymous types.

    For constants, this isn’t an issue.
    The longest built-in typename with constant literals is decimal; that’s not a very long name.

    It is possible to have arbitrarily long enum names which can be used as constants, but the C# compiler team apparently wasn’t concerned for that.
    For one thing, if you’re making a constant enum value, you might as well put it in the enum.
    Also, enum names shouldn’t be too long. (Unlike complex generic types, which can and frequently should)

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

Sidebar

Related Questions

This compiles: int* p1; const int* p2; p2 = p1; This does not: vector<int*>
I just translated this program, #include <stdio.h> int dam[1000][1000]; int main (int argc, const
I would expect an error inside the copy constructor, but this compiles just fine
when doing like this: const int a = 5; I wonder if a will
const static int foo = 42; I saw this in some code here on
I use operator() as a subscript operator this way: double CVector::operator() (int i) const
Given a class like this: class Foo { public: Foo(int); Foo(const Foo&); Foo& operator=(int);
The function header for pthread_create looks like this: int pthread_create(pthread_t * thread, const pthread_attr_t
Given the following: StreamLogger& operator<<(const char* s) { elements.push_back(String(s)); return *this; } StreamLogger& operator<<(int
I just found that when it comes to templates this code compiles in g++

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.