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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:15:24+00:00 2026-05-17T15:15:24+00:00

which one is better or maybe faster for declaring a variable? var ds =

  • 0

which one is better or maybe faster for declaring a variable?

var ds = new Class1();

OR

Class1 ds = new Class1();

I myself believe that second one should be faster coz compiler doesn’t need to look for the type Class1, but some addins like ReSharper always notify me to change Class1 to var.
Can anyone explain me 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-17T15:15:25+00:00Added an answer on May 17, 2026 at 3:15 pm

    They compile to the same IL, so neither will be faster. However, there can be a big difference in readability.

    I tend to favour explicitly declaring the type of the variable, but use var if any of the following cases applies:

    • I’m calling a constructor and the type name is long (particularly with generics)
    • I’m using anonymous types
    • The type name is reasonably long and the initialization expression is long, but still very clear as to what type it will return
    • I want to emphasize the purpose of the code instead of how it achieves its result

    As with many issues of readability, there’s a vast range of opinions about where to use var – from “nowhere” to “everywhere”. Note that you can change what ReSharper recommends for you in the options. (I seem to remember that by default it “recommends” both ways round – so really it’s just making it easier for you to switch.)

    A couple of answers have mentioned the number of keystrokes involved. I think this is the worst possible reason to favour var. I’m rarely, if ever, bottlenecked on typing speed. My coding speed is far more heavily dependent on my understanding of the problem domain, and on how clearly I can imagine the solution. I would far rather enter 2000 keystrokes but end up with an elegant design which is actually represented in 100 characters than type a mere 500 keystrokes for a less-readable 500-character design. Think about the time spent reading the code rather than the mechanics of typing.

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

Sidebar

Related Questions

Which one is better/faster/preferred 1: mov eax, 5 push eax mov eax, [someAddress] push
I'm thinking which way to go and can't decide which one is better. Maybe
Which one of these is faster? Is one better? Basically I'll have two sets
Which one is better (implicit control flow via return or control flow via if
which one is better for implementing chat for the iPhone with users in the
Which one is better from performance view user control or custom control? Right now
Which one is better to use when it come to return value for example
Which one is better at runtime: 1)saving images of size 250X120 in sqlite. 2)Saving
Anyone can tell me which one is better (JAXB or Apache XMLBeans) taking in
My question is, which one is better to use? How to properly use a

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.