It has to do with method overload resolution when calling the ClassB constructor When you call the constructor with no parameters, there is no contention. There is only one candidate, so it is chosen. It is not necessary for ClassA to reference ClassC in this case However, when you call the constructor with one parameter, then at the outset both of the single-parameter constructors are candidates.In order to resolve this call, the compiler needs to know about ClassC For all you know ClassC could contain an implicit conversion operator, for example (Of course we know that in this particular example such an implicit conversion operator wouldn’t fire anyway because there is a perfect match that takes a string — but the method overload resolution rules are defined this way to make them very well-defined and predictable.
Imagine it were designed in such a way that adding a reference could cause your code to suddenly call a different constructor overload. ).
It has to do with method overload resolution when calling the ClassB constructor. When you call the constructor with no parameters, there is no contention. There is only one candidate, so it is chosen.It is not necessary for ClassA to reference ClassC in this case.
However, when you call the constructor with one parameter, then at the outset both of the single-parameter constructors are candidates. In order to resolve this call, the compiler needs to know about ClassC. For all you know, ClassC could contain an implicit conversion operator, for example.
(Of course we know that in this particular example such an implicit conversion operator wouldn’t fire anyway because there is a perfect match that takes a string — but the method overload resolution rules are defined this way to make them very well-defined and predictable. Imagine it were designed in such a way that adding a reference could cause your code to suddenly call a different constructor overload.).
Thanks Timwi, I think all the answers made it pretty clear to me :-) – boomshanka Sep 2 '10 at 12:30.
To resolve the constructor overloads, the compiler needs to know the types involved. I.e. It needs to know ClassC in order to pick the right constructor overload for ClassB.
Thanks for your answer Brian - it concurred nicely with the other answers – boomshanka Sep 2 '10 at 12:28.
It is because ClassC, which you have placed in a separate assembly, is part of the public interface of ClassB since it is a parameter of one of the constructors. You must reference the containing assembly of this type otherwise the compiler has no idea how to resolve the type information. In this specific case the compiler must resolve all parameter types from all constructor overloads so that it can choose the right one, but this is not a member overloading issue per se.
This happens anytime the compiler must resolve type information. It can happen on return types as well.
Even before my edit this answer was not wrong. – Brian Gideon Sep 2 '10 at 11:59 I'm sorry I'm new on stackoverflow but I didn't click anything, just reloaded the page. Maybe that's why it was downvoted?
– boomshanka Sep 2 '10 at 12:09 @boomshanka: No, it was nothing you did. Someone thought this answer was either wrong or more harmful than helpful. I stand behind my answer.
– Brian Gideon Sep 2 '10 at 12:15 Yup so do I, just didn't want to start off by making a complete arse of myself - your answer is greatly appreciated :-) – boomshanka Sep 2 '10 at 12:26.
I forced to reference types in unused constructors because (without quotes):.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.