✅ namespace and using keyword in C#
Hello guys, I have a quick question. I don't understand, when do we use the
using
keyword and the namespace
keyword... can they be used interchangeably ? (don't remember if I once saw a namespace along with a library name... is that even allowed?) .
Now, the namespace, sometimes I saw something like that: namespace {...}
like we have the curly braces but sometimes we don't. My IDE always do the heavy lifting but I wanted to understand what the syntax is :c.
Do we use the keyword using
when we need to use certain libraries? While the keyword namespace
is used to related to certain folders/cs files? I'm a bit confused here :c... what about the namespace {...}
syntax please
6 Replies
the namespace keyword defines the namespace for the classes that you write in that file
the using keyword allows you to access the classes defined in another namespace
oh ok, so is it correct to say that namespace is the thing that allows us to organize our project. Any new cs file created should have a namespace, so that later on we can refer to the classes/methods found in those files using the
using
keyword?
So, using keyword is to use classes/methods from other cs file
namespace keyword is to organize our cs file so that we can refer to them later on?
what about the syntax namespace {...}
pleaseyes
the
namespace {...}
does the same thing
the namespace ...;
is just a short-cut for doing namespace { the rest of the file }
ah ok I see, thanks !
using namespace {}, we can have several namespace within 1 cs file ?
yes
yep I see, thanks !