So I have a method in my code where one of the parameters is a IEnumerable<object>
. For clarity purposes, that will be the only parameter for the example. I was originally calling it with a variable that was a List<string>
, but then realized I only needed those to be char
s and changed the signature of the variable to List<char>
. Then I received an error in my program saying:
Cannot convert source type 'System.Collections.Generic.List<char>'
to target type 'System.Collections.Generic.IEnumerable<object>'.
In code:
// This is the example of my method
private void ConversionExample(IEnumerable<object> objs)
{
...
}
// here is another method that will call this method.
private void OtherMethod()
{
var strings = new List<string>();
// This call works fine
ConversionExample(strings);
var chars = new List<char>();
// This will blow up
ConverstionExample(chars);
}
The only reason that I could possibly think of as to why the first will work, but the second won't is because a List<char>()
is convertible to a string
? I don't really think that would be it, but that's the only long-shot guess that I can make about why this doesn't work.