I got an error today while trying to do some formatting to existing code. Originally, the code had the using directives declared outside the namespace:
using System.Collections.Generic; namespace MyNamespace { using IntPair = KeyValuePair<int, int>; }
When I tried to insert the using directive inside the statement (to comply with StyleCop’s rules), I got an error at the aliasing directive, and I had to fully qualify it:
namespace MyNamespace { using System.Collections.Generic; //using IntPair = KeyValuePair<int, int>; // Error! using IntPair = System.Collections.Generic.KeyValuePair<int, int>; // works }
I wonder what difference there is between the two cases? Does the location of the (import-style) using directive matter?
I used to think that it did not matter, but I always fully qualify using commands.
Edit: Checked the C# spec, section 9.4 says that:
So if System.Collections.Generic and KeyValuePair are treated as peers then KeyValuePair is going to ignore System.Collections.Generic.