![](/img/trans.png)
[英]Why this sub is valid? Why i can pass each Type (String, Interface, Int) to a sub without compiler error as parameter
[英]Why can I pass the wrong interface to a function without compiler errors?
好奇我是否弄乱了一些应该标记此问题的 Visual Studo 设置,或者我是否完全误解了某些东西。
我有一个函数 A,它有 2 个非常基本的接口作为参数:
Function B 有一个参数:
Function A 调用 Function B,将 oConfiguration 作为参数传递。 我似乎在 Visual Studio 中没有收到任何编译器错误或警告,但我当然会收到运行时错误:
无法将“ConfigurationImplementationA”类型的 object 转换为“IEventLogHandler”类型。
打开Option Strict 。
它默认关闭以支持旧版 VB6 代码。 否则,离开它只是痛苦和痛苦,所以不要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.