-1

Today when I was checking all changes with git history diff screen, I found two of my C# files have been added unrelated namespaces.

using System.Windows.Forms;

and

using System.CodeDom;

The two C# files are not referring to those namespaces at all. As I can recall, my activities today are:

  • coding and debugging.
  • renaming variables using refactor.
  • outlining code with ctrl-M, ctrl-O.

Can anyone explain this behavior? Thanks in advance!

----------------Update--------------------

Turns out it is a kind feature of Visual Studio. If I type "Button" in a C# file, "using System.Windows.Forms;" will be automatically added, even after I deleted "Button" afterwards, that using remains. Thank you guys for your comments!

a_pp
  • 39
  • 7
  • You forgot to show files. – Sinatr May 05 '20 at 08:27
  • Hi, you mean the source files? sorry I can't show them, hope someone have some hints with the limited information... – a_pp May 05 '20 at 08:40
  • More likely the assumption *"The two C# files are not referring to those namespaces at all"* is wrong. Or using are side effect of copy/pasting, renaming the file, what else. Use blame, find commit, see (or better ask author) what was added, maybe you get some hints. – Sinatr May 05 '20 at 08:44
  • 1
    Code doesn't get randomly added to your files, only you could have caused this to happen. My guess is you typed in some code that referenced these namespaces when typing in a typo os something and Visual Studio was trying to be helpful. Who knows, that's a guess. Just remove the lines and move on. – DavidG May 05 '20 at 08:49
  • Turns out it is a kind feature of Visual Studio. If I type "Button" in a C# file, "using System.Windows.Forms;" will be automatically added, even after I deleted "Button" afterwards, that using remains. Thank you guys for your comments! – a_pp May 05 '20 at 09:00

1 Answers1

0

Turns out it is a kind feature of Visual Studio. If I type "Button" in a C# file, "using System.Windows.Forms;" will be automatically added, even after I deleted "Button" afterwards, that using remains. Thank you guys for your comments!

a_pp
  • 39
  • 7
  • Get used to autoformat (ctr+k/ctr+d), this speeds up typing a bit, but more importantly you can [enable removing unused using](https://stackoverflow.com/a/56296845/1997232) with it. – Sinatr May 05 '20 at 09:20