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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:13:05+00:00 2026-05-26T14:13:05+00:00

I have a class that’s name is the same as the namespace is is

  • 0

I have a class that’s name is the same as the namespace is is contained within:

Class File ReadModel.cs

namespace App.Core.ReadModel
{
    public class ReadModel 
    {
    } 
} 

Class File MyClass.cs

using App.Core.ReadModel; // this does not work

namespace Something
{
    // using App.Core.ReadModel (Works if I un-comment)

    public class MyClass
    {            
       public void test()
        {
            var x = new ReadModel(); 
        }
    }
}

When trying to instantiate the class, even when trying to add a using directive at the top, the compiler is still unable to resolve the class. HOWEVER, if I put the using statements nested within the namespace, it works fine.

Can someone pls explain why this works? This is a new feature I’ve just discovered.

The error is: App.Core.ReadModel is a namespace but is used like a type

  • 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-26T14:13:06+00:00Added an answer on May 26, 2026 at 2:13 pm

    The difference between

    using System  ;
    using Foo.Bar ;
    
    namespace My.Widget.Tools
    {
      public class MySpecialTool
      {
        ...
      }
    }
    

    and

    using System ;
    
    namespace My.Widget.Tools
    {
      using Foo.Bar ;
    
      public class MySpecialTool
      {
        ...
      }
    }
    

    is that in the first case, the directive using Foo.Bar ; causes the objects in the namespace Foo.Bar to be imported into the unnamed (global) namespace for the compilation unit. In the second case, the using directive imports the objects in the namespace Foo.Bar into the namespace My.Widget.Tools.

    The difference has to do with search order in resolving unqualified references.

    Unqualified references are resolved by first searching within the enclosing named namespace. If the reference is not resolved, then the unnamed (global) namespace for the compilation unit is searched.

    Consider the case where the above namespace Foo.Bar contains a visible class that conflicts with a class contained in the System namespace.

    In the first case, where the Foo.Bar namespace has been loading into the global namespace, you’ll get an error regarding an ambiguous reference if you try to reference the conflicting object: it will search the enclosing namespace first, on not finding it, it will then look into the global namespace and find multiple objects and whine.

    In the second case, the enclosing namespace is searched first, on finding an object of the desired name, the unqualified reference is resolved and the compiler is happy: no conflict.

    Note that you can coerce the search order to the global namespace by qualifying an object reference with the global:: prefix. You can also define your own aliases with the using directive, either for a namespace:

    using io = System.IO ;
    

    or for a type:

    using IntList = System.Collections.Generic.List<int> ;
    

    the caveat with defining an alias for the namespace is that you then have to use the alias to resolve a reference. An alias defined for a type just gives you a [perhaps] shorthand way of naming the type. Probably more useful for generics than anything else. I don’t see a lot of value in doing something like:

    using Row = System.Data.DataRow ;
    

    outside of writing obfuscated C#.

    See also this question: Should 'using' statements be inside or outside the namespace?

    §16 of ISO/IEC 23270:2006 (Information technology — Programming languages — C#) will tell you far more than you ever wanted to know about namespaces and using directives.

    See also this MSDN piece on namespace aliases: http://msdn.microsoft.com/en-us/library/c3ay4x3d(v=vs.80).aspx

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

Sidebar

Related Questions

I have a class that implements IEnumerator<string> . See below: public class MyClass :
I have a class that looks like this public class SomeClass { public SomeChildClass[]
I have class that extends View. private class Draw2D extends View{ public Draw2D(Context context)
I have a class that looks like this: public class Person { public string
I have class that represents users. Users are divided into two groups with different
I have class method that returns a list of employees that I can iterate
I have a class that I want to use to store properties for another
I have a class that map objects to objects, but unlike dictionary it maps
I have a class that I wish to expose as a remote service using
I have a class that creates several IDisposable objects, all of these objects are

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.