+ 1
Namespaces
In the namespaces section, it is said to declare user-defined namespaces using the "using" keyword in another website. So, "namespace sololearn" being a user-defined namespace, why is it not defined? please help.
8 Réponses
+ 1
You dont need to declare a namespace if you work inside that namespace. You declare namespaces only if you want to import their functionality.
+ 1
You only need to define a the namespace with the "using" keyword only if you need some king of functionality from the the extern namespace inside your namespace.
For exaple you have in a project two different namespace like Market and Product which contain diffent classes like MarketClass and ProductClass . You want to use your ProductClass inside the MarketClass but because they have different namespaces you can't just simply create an instance of ProductClass inside MarketClass because they don't know each other. To do that you have in you Market file to include the Product namespace with "using Product". Only then you can use ProductClass inside MarketClass.
I hope you understand
+ 1
You're welcome. If have any other questions don't hesitate to ask.
0
Actually my doubt was that, Assume there is only 1 namespace sololearn, now sololearn is a user-defined namespace so we need to declare it writing "using sololearn"...
We write "using System" to skip writing fully qualified names.
So here y aren't we declaring "using namespace"...
0
What if i want to write my whole code inside that namespace?
0
Then all the functionality of your program is inside that namespace
0
Oh ok sir.i understood it now..Thankyou for sparing time.