Name spaces has nothing to do with access. They do not open or restrict access to anything, they just introduce an additional level in naming of types.
Of course, you are recommended to use namespaces to have more freedom in naming. In other words, you can define name space
Abc
and a type
A
. In this way, you should name this type
Abc.A
, but you also can have some
Cda.A
and, in this way, in the same namespace you can have two
A
s using fully qualified names. Using keyword '
using Abc
' or '
using MyA = Abc.A; using Another.A = Cde.A;
' does not change anything at all; this is only a way to fully-qualify type names or use aliases.
This is only a matter of name resolution, not access.
The access in controlled by the type and member access modifiers
private
,
internal protected
,
internal
and
public
. Read about them and learn to use them, it will solve your problem.
Also, keep in mind that limitation of access does not do any access protection. It is designed to protect you from your own mistakes. Anyone can access any non-public types and members of any assemblies in a regular way using Reflection. This is not even a hack but a standard Reflection functionality.
Access modifiers are only designed to restrict explicit access to types and their members.
[EDIT]
Your
var x
is a stack (local) variable, it is in the inner scope and is not visible from outside at all. The only way to make it visible from a different scope is
anonymous method declared inside this scope, and this is a way to introduce the effect of
closure, see
http://en.wikipedia.org/wiki/Closure_%28computer_science%29[
^].
This is an advanced topic though. Please see my past solutions:
Looping for creating new thread give some problem[
^],
What are Anonymous Types in C#?[
^].
—SA