Namespaces | Sololearn: Learn to code for FREE!
+ 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.

30th Apr 2020, 12:50 PM
naveen areti
naveen areti - avatar
8 Answers
+ 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.
2nd May 2020, 2:21 PM
Abdoul Hakim
Abdoul Hakim - avatar
+ 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
1st May 2020, 7:12 AM
Abdoul Hakim
Abdoul Hakim - avatar
+ 1
You're welcome. If have any other questions don't hesitate to ask.
2nd May 2020, 2:28 PM
Abdoul Hakim
Abdoul Hakim - avatar
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"...
2nd May 2020, 2:12 PM
naveen areti
naveen areti - avatar
0
What if i want to write my whole code inside that namespace?
2nd May 2020, 2:23 PM
naveen areti
naveen areti - avatar
0
Then all the functionality of your program is inside that namespace
2nd May 2020, 2:24 PM
Abdoul Hakim
Abdoul Hakim - avatar
0
Oh ok sir.i understood it now..Thankyou for sparing time.
2nd May 2020, 2:26 PM
naveen areti
naveen areti - avatar