即使在VB.NET中调用无参数函数时也要加上括号? [英] Force parentheses even when calling parameterless functions in VB.NET?

查看:324
本文介绍了即使在VB.NET中调用无参数函数时也要加上括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在调用无参数函数时省略括号.但是,这可能会非常令人困惑,因为开发人员可能会认为语句正在访问属性而不是方法.如果您一次又一次地调用该方法而不是将结果存储在temp变量中,则可能会导致性能下降.

in VB.NET it is possible to omit parentheses when you call a parameterless function. However this can be very confusing because developers could think that a statement is accessing a property instead of a method. this could result in a performance drop if you are calling the method again and again instead of storing the result in a temp variable.

VS2008中是否有一个选项或一个编译器选项来强制在调用方法的语句上加括号?

is there an option in VS2008 or a compiler option to force parentheses on statements that are calling a method?

如果是这样,如果您格式化文档"(菜单:编辑"-高级"),VS是否也可能会自动插入缺少的括号?

and if so, would it be also possible that VS will insert missing parentheses automatically if you "format document" (Menu: Edit - Advanced)?

谢谢,脚趾骨

推荐答案

在VB.Net编译器中没有这样的选项.括号是可选的,使用它们没有任何警告或错误.

No there is no such option in the VB.Net compiler. Parens are optional and there is no warning or error that exist for using a lack of them.

另一个原因是VB.Net是一种试图变得灵活并且使语法不受用户欢迎的语言.这种限制违背了这种普遍的哲学.

The other reason is that VB.Net is a language which tries to be flexible and get the syntax out of the way of the user. This type of restriction goes against this general philosophy.

要考虑的另一个问题是,这不是普遍可实施的限制. VB.Net允许在选项strict设置为off时进行后期绑定.在这些情况下,VB.Net编译器无法提前确定特定调用是属性,语句还是根本不是有效调用.

Another issue to consider is that it's not a universally enforceable restriction. VB.Net allows for late binding scenarios whenever option strict is set to off. In these scenarios it is impossible for the VB.Net compiler to determine ahead of time if a particular call is a property, statement or not a valid call at all.

这篇关于即使在VB.NET中调用无参数函数时也要加上括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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