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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:23:10+00:00 2026-05-25T00:23:10+00:00

Could someone please helpme to understand if the following codes are same. If not

  • 0

Could someone please helpme to understand if the following codes are same. If not what’s the difference between class and interfance instantiation.

IUnityContainer container = new UnityContainer()
UnityContainer container = new UnityContainer()

As far as I understand Inteface has only method signature and if the interface has been implemented by 3 classes. Not too sure which of the 3 instance would be created by first statement above.

Thankyou.

  • 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-25T00:23:10+00:00Added an answer on May 25, 2026 at 12:23 am

    Interfaces can’t be instantiated by definition. You always instantiate a concrete class.

    So in both statements your instance is actually of type UnityContainer.

    The difference is for the first statement, as far as C# is concerned, your container is something that implements IUnityContainer, which might have an API different from UnityContainer.


    Consider:

    interface IAnimal 
    {
        void die();
    }
    
    class Cat : IAnimal 
    {
        void die() { ... }
        void meow() { ... }
    }
    

    Now :

    IAnimal anAnimal = new Cat();
    Cat aCat= new Cat();
    

    C# knows for sure anAnimal.die() works, because die() is defined in IAnimal. But it won’t let you do anAnimal.meow() even though it’s a Cat, whereas aCat can invoke both methods.

    When you use the interface as your type you are, in a way, losing information.

    However, if you had another class Dog that also implements IAnimal, your anAnimal could reference a Dog instance as well. That’s the power of an interface; you can give them any class that implements it.

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

Sidebar

Related Questions

Could someone please help me to understand why the following block of code keeps
Could someone please recommend a simple (as in very easy to understand) charting library
I'm quite new to Spring Framework. Could someone please help me understand the spring
Could someone here please help me understand how to determine when floating point limitations
The following quote is from C++ Templates by Addison Wesley . Could someone please
Could someone please help me understand what the link tags are used for within
Could someone please help me figure out what is wrong with the following code
Could someone please help me out with the following problem in java. I have
I wonder whether someone could help me please. I'm put together the following form
SQL Server Mgmt Studio 2005: could someone please help me understand how to view

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.