Why in the following code error appears?!
using global::System;
namespace System
{
class Program
{
static void Main(string[] args)
{
global::System.Console.WriteLine("Hello World!"); // compiler gives warning conflic for Console and error for WriteLine undefined
}
}
class Console
{
public static void T()
{
}
}
class Test1 : global::System.Console // warning conflict
{
public static void T1()
{
}
}
}
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The global keyword is useful when you want to disambiguate two entities with similar names, e.g. System.Console and TestApp.Console in the example. But you have two types with exactly the same name (System.Console) and global won't help you with that.
If you really want to make this work (and I hope you have a good reason for that, like learning more about C#), you should be able to use the extern alias directive to disambiguate the two assemblies
Than you for the reply. And what is the difference between the followings?
colAlias::Hashtable test = new colAlias::Hashtable();
colAlias.Hashtable test = new colAlias.Hashtable();
This is explained in the spec:
Unlike the regular
.qualifier, the left-hand identifier of the::qualifier is looked up only as an extern or using alias.
If you have an alias colAlias, colAlias::Hashtable is guaranteed to use that alias, while colAlias.Hashtable uses the full name lookup rules, which means it could be ambiguous.
You can see the difference in the following code:
```c#
using Foo = Bar;
namespace Foo
{
class C {}
}
namespace Bar
{
class C {}
}
class Test
{
Foo::C c1; // okay
Foo.C c2; // error
}
```
Hello!
I think you will have a better chance of getting these types of questions answered if you post it on a forum such as StackOverflow. Though I think you did get it answered 😁
I'm going to close the issue.
I am interested though in why you arrived at this article. Are you coming from C++ so the alias::type syntax appealed to you?
Thanks.
Most helpful comment
This is explained in the spec:
If you have an alias
colAlias,colAlias::Hashtableis guaranteed to use that alias, whilecolAlias.Hashtableuses the full name lookup rules, which means it could be ambiguous.You can see the difference in the following code:
```c#
using Foo = Bar;
namespace Foo
{
class C {}
}
namespace Bar
{
class C {}
}
class Test
{
Foo::C c1; // okay
Foo.C c2; // error
}
```