Can remove unused using directive?

  • Thread starter Thread starter Apollo440
  • Start date Start date
A

Apollo440

How to remove unused using directive?

eg)

using System;
using System.Windows.Forms; <- i want to remove this unused using directive

namespace foo
{
:
:
}
 
I'm not sure I understand what you mean but taken literally, you can just
delete it. If it's not being used at all, then there won't be any problems
associated with deleting it or commenting it out. Somehow I'm guessing this
isn't what you meant though so if you could let me know the end goal, I can
probably be of more help.

HTH,

Bill

www.devbuzz.com
www.knowdotnet.com
 
Apollo440 said:
How to remove unused using directive?

eg)

using System;
using System.Windows.Forms; <- i want to remove this unused using directive

namespace foo
{
:
:
}

Rip it out. That's all there is to it.

If get compile errors, then apparently you had some code that was still using
that namespace.

Note that stictly speaking you don't need _any_ using statements, you can just
prepend all types w/ the necessary namespace:

From:

using System.Windows.Forms;
UserControl ctl = new UserControl();

To:

System.Windows.Forms.UserControl ctl = new System.Windows.Forms.UserControl();
 
William Ryan eMVP said:
I'm not sure I understand what you mean but taken literally, you can just
delete it. If it's not being used at all, then there won't be any problems
associated with deleting it or commenting it out. Somehow I'm guessing this
isn't what you meant though so if you could let me know the end goal, I can
probably be of more help.

I suspect Apollo was after the kind of feature Eclipse has had in its
Java development tooling for ages - "organise imports" which sorts the
import statements alphabetically (with preferences to let you separate
out your own imports from system ones and 3rd party ones, etc) and
removes any unused ones. Very handy - I sincerely hope something like
that is in Whidbey.
 
Back
Top