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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:47:32+00:00 2026-06-16T23:47:32+00:00

Are the following equivalent? Is it important to use var type in certain circumstances?

  • 0

Are the following equivalent?
Is it important to use var type in certain circumstances?

Currently using this:

static int ReturnIDfromDb(string sqlString, string outputParam) {
    var connectionString = ConfigurationManager.ConnectionStrings["xxx"].ConnectionString;
    using(var conn = new SqlConnection(connectionString))
    using(var comm = new SqlCommand(sqlString, conn)) {
        ...
    }
}

Is this not more specific?

static int ReturnIDfromDb(string sqlString, string outputParam) {
    var connectionString = ConfigurationManager.ConnectionStrings["xxx"].ConnectionString;
    using(SqlConnection conn = new SqlConnection(connectionString))
    using(SqlCommand comm = new SqlCommand(sqlString, conn)) {
        ...
    }
}
  • 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-16T23:47:33+00:00Added an answer on June 16, 2026 at 11:47 pm

    For the compiler it is the same. Seriously. var turns into hardcoded.

    But still, there are corcumstances where you HAVE to use var, because you DO NOT KNOW THE TYPE.

    IQueryable (LINQ) allows you to project:

    …..

    .Select (x=> new { Name = x.Name; }).ToArray();
    

    In this case you get an array of – anonymous types, so…

    it has to be

    var resultarray

    because you CAN NOT name the type at this point.

    But var is a COMPILER ONLY thing. Code convention of Resharper says: use var, not type. I tend to agree these days.

    After the compiler it is the same.

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

Sidebar

Related Questions

Is there an equivalent to the following: header(Content-type: text/xml); I'm using Google Maps with
What could be a LINQ equivalent to the following code? string[] values = {
Are the following equivalent? private static boolean readAllFiles = false,readAllDirs = false; private static
what would be equivalent to following external style sheet <link href=_css/main.css rel=stylesheet type=text/css media=screen,
Are the following equivalent in C? // #1 struct myStruct { int id; char
The following are equivalent: scala> val f1 = {i: Int => i == 1}
So is the following equivalent in memory usage? System.Threading.Thread.Sleep(500); vs using System.Threading; ... Thread.Sleep(500);
Are the following exactly equivalent? Which idiom do you use and why? $('#form1 .edit-field
Are the following statements equivalent ways for giving up the time slice for the
When filtering a queryset, I'm wondering if the following are equivalent. User.objects.filter(username='josh').filter(email__startswith='josh') User.objects.filter(username='josh', email__startswith='josh')

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.