tags:

views:

98

answers:

1

I've written a class...

namespace SharpQuery
{
    public static class SharpQuery
    {
        public static IEnumerable<HtmlNode> Load(Uri uri)
        {
            // ...

But when I want to call the Load method from inside a different namespace I have to write SharpQuery.SharpQuery.Load even if I put using SharpQuery; at the top. Why is that? How do I get rid of the need to specify the namespace?

+5  A: 

Eric Lippert wrote a series of blog posts saying that you shouldn't have namespaces and classes with the same names. Links here: http://blogs.msdn.com/b/ericlippert/archive/tags/namespaces

He explains it much better than I could.

Niall C.
Yeesh.. 4 blog posts on one little topic? Maybe I'll read through those later, but for the time being, renaming the namespace does indeed fix the problem :) Thanks!
Mark
@Mark: I apologize for answering your question at such length. I didn't have the time to write something shorter.
Eric Lippert
@Eric: Haha.. no need to apologize! I appreciate you taking the time to write those articles for us n00bs :)
Mark
I wish @Eric had written this answer himself, just so I could +1 it for the Mark Twain quote.
Jon Hanna
@Jon: What Mark Twain quote? If you mean my loose translation of *"n'ai fait celle-ci plus longue parceque je n'ai pas eu le loisir de la faire plus courte"* above, that was Blaise Pascal in 1656, not Mark Twain.
Eric Lippert
@Eric, yes of course it was. On the plus side, I shall pretend to myself that I have a finite source of mistakes in a day, and since this one can't cause an app to crash, I shall delude myself that it's a win.
Jon Hanna
@Eric: I didn't know you knew French. Nice skills.
Joan Venge
@Joan: I am Canadian, so I had five years of French in school. I can read and understand simple French if spoken slowly but I am pretty out of practice.
Eric Lippert
@Eric: I am very glad to hear this. I also live in Canada but not Canadian, but hopefully will get the citizenship early next year :O Are you from Vancouver? We should meet one day if you want.
Joan Venge
@Joan: I am from Waterloo, which is near Toronto.
Eric Lippert
@Eric: I bet you went to U of W then? I heard it's the best in CompSci. Now I can attest to that :O
Joan Venge
@Joan: I did go to UW; I have a B.Math in computer science and applied mathematics. And yes, UW has an excellent CS program.
Eric Lippert
@Eric: Thanks for the info. I admire that you have studied math in uni. I always think math is useful in many things especially with 3d stuff that I am working on at work, but by no means I am knowledgeable about it. At least I learn something new every day :O
Joan Venge