KaranGupta
asked on
Namespace pollution global variables
Please explain with example.
ASKER
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
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
C# doesn't have global variables, so namespace pollution is difficult to do, and very rare, but not impossible:
I'm not sure it's possible at all in VB.Net.
//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();
}
}
//}
I'm not sure it's possible at all in VB.Net.
ASKER
Hi
Thanks tgerbert for answering. Any other advice from someone.
Regards
karan
Thanks tgerbert for answering. Any other advice from someone.
Regards
karan
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#.
ASKER
Then what is namespace pollution in vb.net
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi naman_goel
It is possible to create global variables in vb.net. You have the concept called Modules in vb.net
It is possible to create global variables in vb.net. You have the concept called Modules in vb.net
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 .
ASKER
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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
}