Namespace in C# 2005

A sample class for your expert comments.

namespace MyNamespace.
MyBody.MyClass1
{
class1
{
}
}

namespace MyNamespace.MyBody.MyClass2
{
class1
{
}

}


1) From the class view in the VS.IDE, why are they not nested under the namespace of MyNamespace.MyBody

2) Example. Client Application
using MyNamespace.MyBody;

static void Main(string []args)
{
MyClass2.class1 class1 = new
MyClass2.class1(); //compiler returns an error. 'Namespace doesn't exists in this current context'.
}

Your immediate response is much appreciated.


RedDevil


Answer this question

Namespace in C# 2005

  • Michael Kenney

    Ah! Ok, that explains it.

  • amitvjti

    In comparison to 2003, the using statement does bring all nested namespaces. From the class view, it shows that it is nested in the following:
    MyNamespace
    -->MyBody
    -->MyClass1
    -->MyClass2

    Also, from the calling application,
    Example. Client Application
    using MyNamespace.MyBody;

    static void Main(string []args)
    {
    MyClass2.class1 class1 = new
    MyClass2.class1(); //This work in 2003
    }

    In 2005, the class view is as such:
    MyNamespace
    MyNamespace.MyBody.MyClass1
    MyNamespace.MyBody.MyClass2


  • pyefleet

    Hi Matt,

    Apologize for that..It works in VB.NET in 2003 but not C#

  • Ravindra Rajaram

    It does NOT WORK IN VS2003!

    This is the code I used (I had to fix the sample code that you posted, because it does NOT compile):



    using System;

    namespace MyNamespace.MyBody.MyClass1
    {
    class class1
    {
    }
    }

    namespace MyNamespace.MyBody.MyClass2
    {
    class class1
    {
    }
    }

    namespace ConsoleApplication1
    {
    class Test
    {
    [STAThread]
    static void Main(string[] args)
    {
    MyClass2.class1 class1 = new MyClass2.class1();
    }
    }
    }



    In Visual Studio 2003, this code gives the error:

    C:\test\VS2003\CSharp\ConsoleApplication1\Class1.cs(24): The type or namespace name 'MyClass2' could not be found (are you missing a using directive or an assembly reference )

    I don't know what you're doing, but whatever it is, it ain't right.

    Can you cut and paste some actual code from an actual program that demonstrates the "problem" Because the code you did post cannot possibly be correct.



  • Tech Applyyourself

    Re: (2)

    The "using" statement does not (and never has) bring all nested namespaces into scope. It brings only types (classes, structs) into scope. This has NOT changed since C# 1.x.

  • Namespace in C# 2005