.Net Tips - 2

As as developer, I was always wondering how we can remove unused using statements. It is not good practice to add namespaces which are not being used in our code. I was using Resharper to get this done.

.Net has functionality to remove unused namespaces.  Below code is only display
Developer Fusion on command prompt but it using 5 namespaces. This code is only using System namespace for Console class. Other namespace are not used in application.

using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Diagnostics;
namespace
TestApplication
{
   class Program
   {
      static void Main(string[] args)
      {
         string blogNname = "Developer Fusion";
         Console
.WriteLine(blogNname);
      }
   }
}



We can remove unused code by below method

Right mouse -> Organize Usings -> Remove Unused Usings

using.jpg
Now code will be like below

using System;
namespace
TestApplication
{
   class Program
   {
      static void Main(string[] args)
      {
         string blogNname = "Developer Fusion";
         Console
.WriteLine(blogNname);
      }
   }
}

Next Recommended Reading C# Tips