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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:52:03+00:00 2026-05-16T10:52:03+00:00

When I say public static IMyType GetGateWayManager() { IUnityContainer _container = GetContainer(); IMyType _gateWayManager

  • 0

When I say

public static IMyType GetGateWayManager()
{
    IUnityContainer _container = GetContainer();
    IMyType _gateWayManager = _container.Resolve<IMyType>();
    return _gateWayManager;
}

it comes with a warning saying Use implicitly types local variable.

If I change it to

public static IMyType GetGateWayManager()
{
    IUnityContainer _container = GetContainer();
    var _gateWayManager = _container.Resolve<IMyType>();
    return _gateWayManager;
}

it is fine.

Can anyone can tell me why the VS editor thinks it is best practice to use var here?

  • 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-16T10:52:03+00:00Added an answer on May 16, 2026 at 10:52 am

    Who are types for?

    The compiler? Yes, absolutely. The compiler uses types to make it more likely that your program will function correctly at runtime by ensuring the types match up, you’re calling methods that actually exist, and passing them parameters of the right type. Here, the compiler is checking that you’re actually returning something of type IMyType.

    The editor? Again, yes. The editor uses background compilation and type information to help you write code. When you hit . after _container it uses type information to tell you that there’s a Resolve method and what parameters it takes.

    You? Not so much. We’ve already seen that the compiler will ensure that you return something of type IMyType, so why do you care about declaring it as that type when the compiler can work it out and check it for you? Similarly, the editor will tell you about the methods on the container, so why do you care about declaring whether it’s a Unity container or some other type of container, given you already know from the variable name it’s a container of some kind and from the editor that it has a Resolve method.

    There’s no problem with declaring types for locals, but what ReSharper is telling you is that the compiler can work it out, so it’s redundant information, and that your code could be clearer with implicit types and good variable names. For example, is the purpose of this code any less clear than the original sample?

    public static IMyType GetGateWayManager()
    {
        var container = GetContainer();
        var gateWayManager = container.Resolve<IMyType>();
        return gateWayManager;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 526k
  • Answers 526k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Bottom line is, you can't do this. The FROM address… May 16, 2026 at 10:29 pm
  • Editorial Team
    Editorial Team added an answer Use the VIRTUAL_ENV environment variable: setup.cfg [directories] basedirlist = ${VIRTUAL_ENV}… May 16, 2026 at 10:29 pm
  • Editorial Team
    Editorial Team added an answer Solved! Turns out it was pretty simple to resolve. Wireshark… May 16, 2026 at 10:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Let's say I have: public class Fruit { public static List<String> Suppliers { get;
Say I have: class A { public: static void DoStuff(); // ... more methods
Say that I have public static class M { public static string Concat(string a,
say I have: class Test { public static int Hello = 5; } This
Say I have a class: public class R { public static final int _1st
Say I have the following methods: public static void MyCoolMethod(params object[] allObjects) { }
Lets say I have the following code public static string GetXMLValue() { XDocument settingsFile
Newbie Scala Question: Say I want to do this [Java code] in Scala: public
Assume I have the following code: public static class Foo { public static void
I have a web method in one of my aspx pages: [WebMethod] public static

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.