Just curious about it.
Does it matter if I add multiple using
directives at the starting of my code file which I don't use in my code. Like this.
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
//using blah.. blah.. blah..;
public class myClass
{
// Class members
}
Does it have a bad impact on my application's memory usage?
Does it have a bad impact on my application's performance?
I know it is a good practice to remove them and we have short full support of .Net IDE to do so, but I am just curious to know about it.
Extra Using
directives will not have any memory/performance impact on final application - they are nothing but compiler provided shortcuts to deal with long type names. Compiler uses these namespaces to resolve unqualified (or partly qualified) type names to correct types.
Just for the sake of completeness, the IL generated for this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Hello World!");
}
}
}
and this:
class Program
{
static void Main(string[] args)
{
System.Console.Write("Hello World!");
}
}
are exactly the same:
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 13 (0xd)
.maxstack 8
IL_0000: nop
IL_0001: ldstr "Hello World!"
IL_0006: call void [mscorlib]System.Console::Write(string)
IL_000b: nop
IL_000c: ret
} // end of method Program::Main
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With