I have a question regarding namespace names and classes:
If I have a class called cVeloConnect in namespace VeloConnect.
e.g.
namespace VeloConnect
{
public class cVeloConnect
{
// Some content
public void PrintMe();
}
public class cSomeClass
{
// Some content
}
}
And now I want to create a new instance of cVeloConnect, calling this instance VeloConnect, I cannot access the VeloConnect namespace anymore…
e.g
VeloConnect.cVeloConnect VeloConnect = new VeloConnect.cVeloConnect();
VeloConnect.PrintMe();
// The below thing is not possible
VeloConnect.cSomeClass MyClass = new VeloConnect.cSomeClass();
How can I access the other class, if I don’t want to rename the namespace or my previous instance ?
Well, one option is to follow naming conventions to avoid this sort of thing – your classes shouldn’t start with
c, and your local variables would normally start with a lower case letter.To avoid having to use the namespace at all in the declaration, you can just use a
usingdirective at the top of your code. Or if you really want to specify the namespace, you could useglobal:::In general though, I don’t like seeing namespaces within my actual code – I prefer having
usingdirectives so I can just use the simple names in the body of the code. Either way, I would strongly urge you to start following the .NET naming conventions.