On Fri, 27 Jan 2012 09:18:53 -0800 (PST), Andy wrote:
> You've defined your list as being able to hold only string objects.
> When you try to pass something to this list that isn't a string
> object, .NET will automatically invoke the .ToString() method on your
> non-string object to turn it into a string. [...]
This is not true at all. The point of generics, and it will apply to
List<string> as well, is that at _compile-time_ you will be prohibited from
using objects not already typed as the type used for the generic.
This means that it will be a compiler error to attempt to add anything not
already typed as "string" to the List<string>, and you also will not be
able to assign members of the List<string> to anything except a variable of
type "string".
No automatic conversion will occur.
In addition: even if the "automatic conversion" was true, it wouldn't apply
here. The OP is looking at the List<string> instance itself, not objects
contained by that instance.
Pete