0

I have an ambiguous reference between two methods from different classes.

This classes are in different namespaces that share the same structure like:

MyApp.Models.Folder1.Class1
MyApp.Models.Folder2.Class2

Why I can't use like this?

using MyApp.Models;
//and use this static method
Folder1.Class1.StaticMethod();

And is there any way to use a namespace just for a method? like:

[using(MyApp.Models.Folder1)]
public ContentResult SomeGetMethod(){
    if(Class1.StaticBooleanMethod()) return "nice baby!";
    return "that was horrible!";
}

1 Answer 1

1

Why I can't use like this?

From the MSDN documentation, a using directive does not give you access to any namespaces that are nested in the namespace you specify.

And is there any way to use a namespace just for a method? like:

There is no way to do this, however you can fully qualify the name:

if (MyApp.Models.Folder1.Class1.StaticBooleanMethod()) return "nice baby!";

Or use an alias:

using Folder = MyApp.Models.Folder1;
...
if(Folder.Class1.StaticBooleanMethod()) return "nice baby!";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.