Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top