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

  • Home
  • SEARCH
  • 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 6337193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:12:23+00:00 2026-05-24T19:12:23+00:00

I am creating a little Math library for myself contained within a single project

  • 0

I am creating a little Math library for myself contained within a single project and am running into some issues with namespaces. I have the project MyMathLib and the top level namespace:

namespace MyMathLib
{ ... }

and in a separate file…

namespace MyMathLib.Addition
{ ... }

and…

namespace MyMathLib.Subtraction
{ ... }

In the MyMathLib.Subtraction namespace I have a method that needs to use a static method SomeClass.Work() defined in MyMathLib.Addition so I included using MyMathLib.Addition at the beginning of the Subtraction file. But when I try to use the method it would like me to first qualify it with Addition.SomeClass.Work() and I want to be able to just type SomeClass.Work(). What am I doing wrong?

Thanks!

EDIT

Thanks for the suggestions! In each file, I actually named the class after the namespace (i.e. in the namespace MyMathLib.Addition is a static class Addition and in MyMathLib.Subtraction there is a static class Subtraction). Apparently this is what caused the issue (looking back, I should have stated this instead of using SomeClass). If I change the namespace to MyMathLib.MyAddition while keeping the static class as Addition, the using MyMathLib.MyAddition works as I want; that is, I can now just type Addition.Work() in my static Subtraction class. I’ve seen classes named the same as it’s containing namespace before, could someone maybe explain why this is causing an issue? Shouldn’t the compiler be able to determine whether I want to use the namespace or the class from the context of the code?

  • 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-24T19:12:24+00:00Added an answer on May 24, 2026 at 7:12 pm

    I’m guessing that you either have two classes called SomeClass that are both in namespaces you reference, or you have a variable or property named SomeClass. Either of these situations would make it impossible for the compiler to know that you’re trying to call the static MyMathLib.Addition.SomeClass.Work() method, but the specific solution the compiler is suggesting makes it seem more likely to be the former.

    Update

    Seeing your edit, that makes sense. If you were using these in a namespace outside of MyMathLib, then you would still be able to avoid this namespace conflict. However, because you are inside the MyMathLib.Subtraction namespace, the compiler will implicitly consider any portion of the namespace "above" you to take precedence over class names. In this case, when you say "Addition", the compiler will look for the following items to resolve the name:

    1. A class explicitly identified by a using ... = ... directive.
    2. MyMathLib.Subtraction.Addition namespace.
    3. MyMathLib.Addition namespace.
    4. Addition namespace.
    5. Any classes in the namespaces identified by using statements.

    In this case, you’re hitting #3 before #4, so you should be able to work around it either by renaming the class or namespace, or by using Yahia’s suggestion (#1):

    using Addition = MyMathLib.Addition.Addition;
    

    Update 2

    After looking at the article you linked to, it sounds like the explicit using statement still won’t work. I guess item #1 actually gets evaluated down around item #4 instead. Bummer. You can use an alias to give the class a different name locally:

    using Add = MyMathLib.Addition.Addition;
    
    ...
    
    var add = new Add();
    

    But the best solution is still probably just to avoid the namespace collision entirely by changing your namespace or class name.

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

Sidebar

Related Questions

I am creating a little testing component and am running into a problem Basically
I am creating a little TV guide for myself and I have a list
I'm creating a little photo sharing site for our home's intranet, and I have
Seems I've outdone myself. All the while I was creating this pretty little 'latest
I'm creating a game with points for doing little things, so I have a
I'm creating a little Java application which should have a progress indicator with percentages.
I'm creating a little puzzle game just as a hobby project but the project
I'm creating a map editor for a little game project that I'm doing. Considering
I'm creating a little calendar app in Django. I have two model classes; Calendar
Picture this: you are creating a little module that people can incorporate into their

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.