Generic method isn't choosing the most specific constructor signature?
c#, generics
Solution
Overload resolution is done at compile time, not at runtime. So when you call `new C(v)` from the `Add<T>` method, the compiler doesn't know that `T` will actually be `Guid`, so it uses the only overload that is guaranteed to be compatible, which is `public C(object c)`
Problem
When I use a method with a generic parameter to create another object, the generic object isn't selecting the most specific constructor. That sounds confusing, so here's some sample code to demonstrate what I mean... Can anyone explain why the output of this program is: ``` guid <-- easy - no problem here object <-- WHY? This should also be "guid"?! ``` ...and how to make the generic `Add<T>` function call the correct constructor of `C`?? Here's the code: ``` void Main() { B b = new B(); C c = new C(Guid.Empty); b.Add<Guid>(Guid.Empty); } public class B { List<C> cs = new List<C>(); public void Add<T>(T v) { cs.Add(new C(v)); } } public class C { public C(Guid c) { Console.WriteLine("guid"); } public C(object c) { Console.WriteLine("object"); } } ```