C# DataGridViewSelectedCellCollection 无法隐式转换为 IList

发布于 2025-01-16 22:33:15 字数 873 浏览 2 评论 0原文

观察:

  1. DataGridViewSelectedCellCollection 实现 IListICollectionIEnumerable
  2. DataGridViewSelectedCellCollection 的 API 中没有实现所有这些接口的所有函数(例如缺少 IList.Add

问题:

  1. DataGridViewSelectedCellCollection 怎样才能不 实现所有这些接口呢?实现接口中的所有函数?
  2. 为什么编译器不能隐式转换为接口(或者至少在编译器消息中提供存在歧义的详细信息)

? 其中 selectedDataGridViewSelectedCellCollectioncellDataGridViewCell

这不会编译: selected.Add(cell ); 但这样做是这样的: ((IList)selected).Add(cell);

来源:
DataGridViewSelectedCellCollection 文档

Observations:

  1. DataGridViewSelectedCellCollection implements IList, ICollection, and IEnumerable.
  2. DataGridViewSelectedCellCollection does not have all the functions in its API to implement all of these interfaces (e.g. it's missing IList.Add

Question:

  1. How can DataGridViewSelectedCellCollection not implement all the functions in the interface?
  2. 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);

Sources:
DataGridViewSelectedCellCollection docs

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文