Namespace pollution global variables

Please explain with example.
KaranGuptaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Naman GoelConnect With a Mentor Software engineer 1Commented:
that is not possible in any .net technology. The only problem you may get is what I explained earlier.
0
 
Naman GoelSoftware engineer 1Commented:
When you write using namespace X, the names in that namespace are made visible
in the current scope.

Say,
namespace X{
class Y{
};
}
class Y{
};
int main(){
Y y; // OK
}

Next write using namespace X, so class Y gets introduced in the current scope.

namespace X{
class Y{
};
}
using namespace X;
class Y
{
};
int main{
Y y; // Error...Y is ambiguous
}
0
 
KaranGuptaAuthor Commented:
Hi naman_goel

The example you have given is about the class ambigousness in namespace. It is not about namespace pollution in case of global variable.


Regards
Karan Gupta
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Todd GerbertIT ConsultantCommented:
C# doesn't have global variables, so namespace pollution is difficult to do, and very rare, but not impossible:
//namespace ConsoleApplication1
//{
	delegate void System();
	class Program
	{
		static void Main(string[] args)
		{
			// The "System" namespace is unavailable, because it conflicts
			// with the "System" delegate, which also appears in the global namespace
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
		}
	}
//}

Open in new window


I'm not sure it's possible at all in VB.Net.
0
 
KaranGuptaAuthor Commented:
Hi
Thanks tgerbert for answering. Any other advice from someone.

Regards
karan
0
 
Naman GoelSoftware engineer 1Commented:
yes, even I agree with tgerbert, C# is component oriented language like java where we can't declare global variable outside the scope of class, and that's why we don't have such type of namespace pollution in c#.
0
 
KaranGuptaAuthor Commented:
Then what is namespace pollution in vb.net
0
 
KaranGuptaAuthor Commented:
Hi naman_goel

It is possible to create global variables in vb.net. You have the concept called Modules in vb.net
0
 
Todd GerbertIT ConsultantCommented:
But you can't declare variables outside of a module, so you can't declare them in the Global namespace.  If you declare a global variable in VB.Net it's fully qualified name becomes Global.Module1.TheVariable.
0
 
KaranGuptaAuthor Commented:
Hi

Ok noted. If we say that there is a variable inside the module in vb.net can there be any namespace pollution in that case
0
 
Todd GerbertConnect With a Mentor IT ConsultantCommented:
No, because the variable is never in the Global namespace. In VB.Net you can never have Global.YourVariable, it would always be Global.Module1.YourVariable, or Global.Class1.YourVariable.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.