VB.net在调用时在参数参数中定义常量 [英] VB.net Defining constants in parameter arguments at call time

查看:166
本文介绍了VB.net在调用时在参数参数中定义常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有

公共函数DoSomething(将i表示为整数)

有什么语法可以在调用时声明参数.

例如

Public Sub SomeSub
...
DoSomething(const SomeInteger = 5)
....
结束子



Public Sub SomeSub
...
DoSomething(SomeInteger as integer = 5)
...
Sub Sub

Say I have

Public Function DoSomething(dim i as integer)

Is there some kind of syntax where I can declare the parameter at call time.

eg

Public Sub SomeSub
...
DoSomething(const SomeInteger = 5)
....
End Sub

or

Public Sub SomeSub
...
DoSomething(SomeInteger as integer= 5)
...
End Sub

推荐答案

确实存在,如果您使用的是这种语言,您应该知道它:
http://msdn.microsoft.com/en-us/library/f25e2b6b%28v = vs.110%29.aspx [ ^ ].

老实说,如果您在尝试编写程序之前只是阅读一本语言手册,而只是使用一个引用(显然是MSDN,提供了所有这些),而不是问这样的问题,那么您可以更好地利用自己的时间.

另外,您也不正确.试想一下:那些默认值在编译过程中是已知的;没有在调用时定义常量"之类的东西,否则您不能将它们称为常量".即使在您自己的示例中也并非如此-它们是正常常数.显然,也允许使用常量表达式(因为没有理由不使用常量表达式:编译器可以始终对常量表达式求值).

—SA
Such thing does exist, and you should know it if you are using this language:
http://msdn.microsoft.com/en-us/library/f25e2b6b%28v=vs.110%29.aspx[^].

Honestly, you could much better use your time if you simply read a language manual before trying to write a program and just used a reference (MSDN, apparently, provides all that), instead of asking such questions.

Also, you don''t understand it right. Just think about it: those default values are known during compilation; there is no such thing as "defining constants at call time", otherwise you could not call them "constant". This is not the case even in your own example — they are normal constants. Apparently, constant expression are also allowed (because there are no reason not to have them: the compiler can always evaluate constant expressions).

—SA


这篇关于VB.net在调用时在参数参数中定义常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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