【发布时间】:2011-07-06 20:10:18
【问题描述】:
我正在更新一个遗留应用程序,它正在从另一个项目中读取一个 dll 以获取项目的 Dictionary(of Guid, String) 并使用它们。
要求已更改,返回 Dictionary 的方法现在返回 IList。
这是 this 的奇怪行为;智能感知不会引发强制转换错误,编译器也不会。当它尝试将 Dictionary 设置为 IList 时,它直到运行时才会抛出错误。
例子:
Dim someDictionary As Dictionary(Of Integer, String) = New Dictionary(Of Integer, String)
Dim someList As IList(Of Integer)
someDictionary = someList
知道为什么编译器没有捕捉到这个吗?
【问题讨论】:
-
因为 VB.Net 不检查 类型安全 - 我从未认为 VB 是一种强类型语言。 VB 允许大量隐式转换,C# 在您尝试编译之前很久就会尖叫。
-
@IAbstract:启用 Option Explicit 和 Option Strict 后,VB 的类型非常强...
-
@Jon: 我想我是选项错了;)
标签: .net vb.net compiler-errors