C# DataGridViewSelectedCellCollection 无法隐式转换为 IList
观察:
DataGridViewSelectedCellCollection
实现IList
、ICollection
和IEnumerable
。DataGridViewSelectedCellCollection
的 API 中没有实现所有这些接口的所有函数(例如缺少IList.Add
问题:
DataGridViewSelectedCellCollection
怎样才能不 实现所有这些接口呢?实现接口中的所有函数?- 为什么编译器不能隐式转换为接口(或者至少在编译器消息中提供存在歧义的详细信息)
? 其中 selected
是 DataGridViewSelectedCellCollection
, cell
是 DataGridViewCell
这不会编译: selected.Add(cell );
但这样做是这样的: ((IList)selected).Add(cell);
Observations:
DataGridViewSelectedCellCollection
implementsIList
,ICollection
, andIEnumerable
.DataGridViewSelectedCellCollection
does not have all the functions in its API to implement all of these interfaces (e.g. it's missingIList.Add
Question:
- How can
DataGridViewSelectedCellCollection
not implement all the functions in the interface? - Why can't the compiler implicitly cast to the interface (or at least provide details in the compiler message that there's ambiguity)?
Example:
Where selected
is DataGridViewSelectedCellCollection
and cell
is DataGridViewCell
This doesn't compile: selected.Add(cell);
But this does: ((IList)selected).Add(cell);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论