I believe I have a fundamental misunderstanding of namespace hierarchy, causing almost the opposite problem to this question: vb.net System namespace conflict with sibling namespace
I have two .cs files containing the below:
File 1
namespace Parent.Math
{
public class Foo { }
}
File 2
using System;
namespace Parent.Child
{
public class Bar
{
public Bar()
{
Console.WriteLine(Math.Sqrt(4));
}
}
}
File 2 presents the error: CS0234 - The type or namespace name 'Sqrt' does not exist in the namespace 'Parent.Math'
Why does the compiler assume Math to be reference to the sibling namespace and not the member of the explicitly referenced System namespace? The behavior is as if parent namespaces are automatically referenced. Is this correct? I would of at least expected an ambiguity error.
Thank you.
System;inside the namespace. If you want to know the gory details,14.5.3 Using namespace directivesin the ecma specsAny reason why this would be "bad practice"?Partly because it makes the code slightly harder to review (vs being explicit aboutSystem). But honestly, it is going to be hard to review regardless due to the clash.