var words = new List<object>();
public void WriteWords(IList<Word> words)
{
foreach (var word in words)
{
}
}
WriteWords(words.Select(item => (Word)item).ToList()));
1.words是个object类型
2.方法WriteWords的参数类型是IList<Word>
3.调用WriteWords方法需要把List<object>转换成IList<Word> words
WriteWords((List<Word>)words);
这样是行不通的,不能直接把List<object>转换成List<Word>,需要将List<object>每个object遍历,每个object转换成Word类型,再从新转换成List