What happens at runtime when number of namespaces are used in the program? Are the classes from the namespaces loaded entirely or the class used in program get loaded? What if there are unused namespaces present in the program?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Namespaces are really more of a compile time construct then a runtime construct. Putting classes into a namespace primarily only affects the name of the class. The “fully qualified name” of any class is actually its namespace hierarchy(separated by periods
.) followed by the actual class name. You con’t “load” a namespace at runtime, the entire concept doesn’t exist.When you compile a program, if you compile it to a library (.dll) you can add a reference to that .dll, in which case all of the classes in that dll are “accessibe” in your program. As for whether they’ll be loaded, it’s certainly possible for them to be loaded, but chances are due to lazy initialization unused classes won’t have a significant impact on performance.
When you add a
usingstatement to the top of a file for a namespace, it doesn’t “load” that namespace. It will be used by the compiler to resolve all “unqualified” class names to “fully qualified” class names (at compile time). If you used just fully qualified class names in the first place you wouldn’t need anyusings (but that really clutters up your code, so you should add them anyway).