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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:14:42+00:00 2026-06-13T03:14:42+00:00

What is the main difference between the following two declarations? public string Name {

  • 0

What is the main difference between the following two declarations?

public string Name
{
  get { return "Settings"; }
}

and

public const string Name = "Settings";

Aren’t both prevented from being changed?

  • 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-13T03:14:43+00:00Added an answer on June 13, 2026 at 3:14 am

    The first is a property which only provides a get accessor. This is specified per instance.

    The second is a compile time constant. At compile time, it will be replaced with "Settings", so it is not really a member of the type at all.

    The const declaration does have the advantage of eliminating a method call (as it’s just a compile time constant value), however, the property call will likely get eliminated by the JIT at runtime.

    The property declaration has the advantage of allowing you to change how this works later, without breaking compatibility – even binary compatibility. In order to see a change in the const value, a full recompilation of everything that uses it would be required, even if it’s in separate assemblies.

    Basically, a public const is probably a good idea, but only if this is a value that will never change – not a value that will never change during the runtime of the program, but that will never change anywhere, at any time. Int32.MaxValue is a good example – this has a specific meaning that is based on the Int32 type itself – there’s no way that this would ever change. As such, it makes sense as a public const. In your case, "Settings" may be something you’d want to change eventually – if that’s the case, then encapsulating it in a property makes sense.

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

Sidebar

Related Questions

What is the main difference between these following two ways to give a method
What's the difference between the following two cases? std::pair<int,std::string> example_1 (std::make_pair (1,foo)); int value_1
What is the difference between the following two assignments? int main() { int a=10;
The following string of mine tried to find difference between two strings. But it's
Why is the difference between the two addresses wrong? http://codepad.org/NGDqFWjJ #include<stdio.h> int main() {
What is the difference between following two? 1# trait B extends A { }
I am trying to find the difference between the following two sets: A =
can somebody please tell me the difference between the following two code snippets: //Code
I came across a difference in speed using the following two structs: public struct
Im trying to see a performance difference between the following two programs (was expecting).

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.