Classes Hidden from Main...

  • Thread starter Thread starter agro_r
  • Start date Start date
A

agro_r

Examine this code...


using System;

class Foo
{
public int i = 0;
}

namespace Joe
{
class Foo
{
public int i = 10;
}
class Start
{
static void Main()
{
Foo bar = new Foo();
Console.WriteLine(bar.i); // will print 10
}
}
}


My question is, how can Main() access the Foo class which resides in
the "root" namespace, other than using this statement:

[code:1:adc9efdc6b]
using OuterFoo = Foo;
[/code:1:adc9efdc6b]

In C++ we can use ::Foo but I haven't found such mechanism in C#.

Thanks a lot...
 
Can you be more specific about what does not work? I have just tried it (not use your workaround) and everything goes OK

Petr
 
My question is, how can Main() access the Foo class which resides in
the "root" namespace, other than using this statement:

<snip>

I suspect it can't - but personally, that doesn't bother me. You should
avoid using the root namespace for anything other than simple test/toy
code, and if you *have* to use a library from somewhere else which uses
the root namespace, you can use the workaround you gave.
 
Hi argo_r,

First to answer your question IFAIK there is no way to do that with the
current version of C#.
And as Jon said you shouldn't use that. You will have a name conflict if
there is a type with the same name decalred in the gobal namespace, but in
different assembly

Anyways, what is that?
[code:1:adc9efdc6b]
.....
[/code:1:adc9efdc6b]
It doesn't even compile.... Do you know what that means?
Where do you put this?
 
Back
Top