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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:53:51+00:00 2026-06-09T15:53:51+00:00

I created a const for a value previously explicitly stated several times in my

  • 0

I created a “const” for a value previously explicitly stated several times in my code:

private static readonly int QUARTER_HOUR_COUNT = 96;

When I did a search-and-replace of 96 for QUARTER_HOUR_COUNT, I inadvertently also replaced the declaration, so it became:

private static readonly int QUARTER_HOUR_COUNT = QUARTER_HOUR_COUNT;

…yet it compiled. I would think that it would disallow that. Why was it accepted by the compiler as a valid declaration?

  • 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-09T15:53:52+00:00Added an answer on June 9, 2026 at 3:53 pm

    I would think that it would disallow that. Why was it accepted by the compiler as a valid declaration?

    Presumably because the language specification allows it. Do you have a specific rule in the language specification which you think prohibits it?

    If your question is really “why doesn’t the language specification prohibit this” – I suspect it’s because it’s probably quite hard to make sure you only prohibit things you really want to prohibit, while actually prohibit all such things.

    You could argue that for simple cases of assignment directly back to itself, it would be good to have a special case in the language spec, but it would introduce complexity into the language for relatively little benefit.

    Note that even if you didn’t get an error, I’d expect you to get a warning – something like this:

    Test.cs(3,33): warning CS1717: Assignment made to same variable; did you mean to assign something else?

    Also note that if you make it a const instead of just a static readonly variable, then you do get a compile-time error:

    Test.cs(3,23): error CS0110: The evaluation of the constant value for ‘Program.QUARTER_HOUR_COUNT’ involves a circular definition

    Also note that by .NET naming conventions, this ought to be called QuarterHourCount, rather than having a SHOUTY_NAME.

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

Sidebar

Related Questions

How can I create a const boost matrix? The following did not work: const
The function header for pthread_create looks like this: int pthread_create(pthread_t * thread, const pthread_attr_t
Created Private Key & Self signed certficate in a Key Store keytool -genkey -alias
I created cookie with server side code (c#) and it was shown in chrome
Hey all, I'm working on cleaning up my code from previous semesters. Previously I
I created a table Test create table test ( id int identity(1,1) not null,
when for Perperty created a private field,Do it is compulsor?? and when do not
I have the following code where I wanted to eliminate the element I created
In C++ is a return value guaranteed to be created before automatic variables in
Here is the code which gives me the error: TAdvSmoothDockItems = class(TCollection) private FOwner:

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.