没有As子句的函数没有给出任何错误。 [英] Function without As clause not giving any error.

查看:111
本文介绍了没有As子句的函数没有给出任何错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub Form1_Load(sender as Object,e As EventArgs)Handles MyBase.Load



Dim a As String = GetMsg(a)



''其他任务



结束次级



私人功能GetMsg()

返回5

结束功能





---------------------------------------



在上面的代码中为什么编译器没有给GetMsg函数带来任何错误。实际上我将一个参数传递给GetMsg函数但是GetMsg函数不接受任何函数然后为什么编译器没有给出任何错误?

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim a As String = GetMsg("a")

''Other task

End Sub

Private Function GetMsg()
Return "5"
End Function


---------------------------------------

In above code why the compiler not giving any error for GetMsg function.Actually I am passing one parameter to GetMsg function but GetMsg function does not accept any function then why compiler not giving any error?

推荐答案

这是VB.NET中的一个功能,是VB的遗产。默认情况下,选项strict是关闭的,它不会警告您类型不匹配。在这种情况下,GetMsg返回隐式转换为String的对象。



转到Project->属性 - >编译,找到Options strict并将其设置为on。然后检查下面的警告配置并确定您是否希望某些类型的通知是警告,错误或忽略。



如果这有帮助,请花些时间接受解决方案。谢谢。
This is a "feature" in VB.NET, legacy of VB. By default, option strict is off and it will not warn you about type mismatch. In this case, your GetMsg returns object which is implicitly cast into String.

Go to Project-> Properties -> Compile, find Options strict and set it to on. Then check the Warning configurations below and decide if you want certain types of notifications to be warning, error or ignored.

If this helps please take time to accept the solution. Thank you.


这篇关于没有As子句的函数没有给出任何错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆