Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to figure out.How to use global namespace.I have some code.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aliasname = Boxnamespace.Bunch;
namespace aliaoperator
{
    class Program
    {
        static void Main(string[] args)
        {
            Boxnamespace.control.controlclass.Controlmethod();
            global::System.Console.Read();
        }
    }
}
namespace System
{
    class Console
    {

    }
}
namespace Boxnamespace
{
    namespace Aliasname
    {
        class myclass
        {
            public static void Writesomething() 
            {
         
            }
        }
    }

    namespace Bunch
    {
        class myclass
        {
            public static void Writesomethingelse()
            {
                global:: System.Console.WriteLine("Hello2");
            }
        }
    }
    namespace control
    {
        class controlclass
        {
            public static void Controlmethod()
            {
                Aliasname.myclass.Writesomething();
                Aliasname::myclass.Writesomethingelse();
                global::System.Console.WriteLine();
            }
        }
    }
}
And i get error System.Console doesn't have implementation for WriteLine.How to fix it.
Posted
Comments
CHill60 19-Jan-15 8:45am    
Try removing namespace System
{
class Console
{

}
}
Inimicos 19-Jan-15 9:18am    
I know that this is solution,and i should avoid of using name "System" in namespace implementation but,i want to figure out,how to use global namespace,when i have another namespace with the same name.
E.F. Nijboer 19-Jan-15 12:30pm    
I don't think it is possible and also something that shouldn't be done. Maybe you can try creating an alias for the System namespace.

1 solution

You cannot use the global namespace qualifier to resolve the namespace clash because your System.Console class de facto replaces the one in the global namespace.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900