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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:12:58+00:00 2026-05-11T04:12:58+00:00

Help me settle an argument here. Is this: SqlCommand cmd = new SqlCommand( sql

  • 0

Help me settle an argument here.

Is this:

SqlCommand cmd = new SqlCommand( 'sql cmd', conn); 

treated exactly the same as this:

const string s = 'sql cmd'; SqlCommand cmd = new SqlCommand( s, conn); 

Ie. does it make a difference if I state specifically that the string s is a const.

And, if it is not treated in the same way, why not?

  • 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. 2026-05-11T04:12:58+00:00Added an answer on May 11, 2026 at 4:12 am

    In the latter snippet, it’s not that the string is const – it’s that the variable is const. This is not quite the same as const in C++. (Strings are always immutable in .NET.)

    And yes, the two snippets do the same thing. The only difference is that in the first form you’ll have a metadata entry for s as well, and if the variable is declared at the type level (instead of being a local variable) then other methods could use it too. Of course, due to string interning if you use ‘sql cmd’ elsewhere you’ll still only have a single string object in memory… but if you look at the type with reflection you’ll find the const as a field in the metadata with the second snippet if it’s declared as a constant field, and if it’s just a local variable it’ll be in the PDB file if you build one.

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

Sidebar

Related Questions

Help from the SQL Gods Required Table 1 - DistinctQuotes This tables holds information
Help settle the debate that's going on in the comments at this question about
Help me settle an argument with a coworker... We’re using Zend Framework and PHP
Help, I'm trying to create a new post in my wordpress blog with custom
Help me settle a dispute with a coworker: Does setting a variable or collection
I wish to settle my long term problem by this question and hope you
In advance, I would like to say thanks for the help. This is a
I'm a bit new to ASP.NET. Actually, I'm a marginalized VB/SQL programmer who is
Please help us settle the controversy of Nearly everything is an object ( an
I'm sorry this is a very long question. I'm looking for help from people

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.