I've got a namespace in a referenced project, Project.Base
, and someone thought it would be a good idea to declare their own generic List class in that namespace.
Now I have a code file that starts out:
using System.Collections.Generic;
using Project.Base.Sub;
The Project.Base
namespace is never actually formally used; just a nested namespace within it. System.Collections.Generic
is formally used. But for some bizarre reason, when I declare a method whose return type is List<T>
, it interprets that as a Project.Base.List<T>
rather than a System.Collections.Generic.List<T>
!
This seems incredibly counterintuitive to me. Does anyone know what's going on and how to fix it?
EDIT To reproduce:
using System;
using System.Collections.Generic;
using Project.Base.Sub;
namespace Project.Base
{
public class List<T> { }
}
namespace Project.Base.Sub { }
namespace Project.Base.Sub2
{
public class P
{
public static void Main()
{
var list = new List<int>();
Console.WriteLine(list.GetType().Namespace);
Console.Read();
}
}
}
(Note that the code in question is in a different sub-namespace of Project.Base. This appears to be significant.)