Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is 'using namespace' means load entire types under that namespace

Tags:

c#

.net

say i have a code

using System;
using System.Windows.Forms;

class TestApp
{
   static void Main()
   {
     Console.WriteLine("Testing! 1, 2, 3");
     MessageBox.Show("Hello...");
   }
}

will the using System & System.Windows.Forms means load all types (within those namespaces) at runtime, although im using only to print on console and show a messagebox ?

and also will there be any memory consumed for loading those required types (Console & MessageBox) at the execution time...

[ and there will be some block of code (within Console) still unutilized by the source code but still will it be loaded ? ]

so any clue on what's happening behind the scenes (atleast for the above 10 lines of code)would be helpfull...

like image 384
x-code Avatar asked Mar 24 '23 01:03

x-code


1 Answers

using statements are compile time only statements allowing the compiler to find referenced types without specifying the fully qualified name at every use, they will not make anything load at runtime that otherwise wouldn't load if referencing the same type directly.

like image 143
Joachim Isaksson Avatar answered Apr 26 '23 13:04

Joachim Isaksson