Reputation: 9084
For the best website performance is using: (for example)
Telerik.Web.UI.RadChart ResultChart = new Telerik.Web.UI.RadChart();
Is faster than :
using Telerik.Web.UI;
and
RadChart ResultChart = new RadChart();
and what if i used the using
directive in many modules in ASP.net page, does the compiler use it once?
Upvotes: 0
Views: 56
Reputation: 98750
There is no difference.
using
statements makes your code short and more readable. There is no problem if you use it in many modules. Same IL (Intermediate Language) code created for both version. You can check it these two piece of code and their IL codes;
using System;
namespace Programs
{
public class Program
{
public static void Main(string[] args)
{
string s = "Foo";
}
}
}
.method public hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 8 (0x8)
.maxstack 1
.locals init ([0] string s)
IL_0000: nop
IL_0001: ldstr "Foo"
IL_0006: stloc.0
IL_0007: ret
} // end of method Program::Main
namespace Programs
{
public class Program
{
public static void Main(string[] args)
{
System.String s = "Foo";
}
}
}
.method public hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 8 (0x8)
.maxstack 1
.locals init ([0] string s)
IL_0000: nop
IL_0001: ldstr "Foo"
IL_0006: stloc.0
IL_0007: ret
} // end of method Program::Main
Upvotes: 2
Reputation: 499002
It makes no difference. The compiled IL will contain the fully qualified name every time the type needs to be used.
The using
statement just makes your code file shorter and easier to read.
The number of times a directive appears in your code also makes no difference - just the fact that the assembly that it is in is referenced by the project is enough.
Upvotes: 3