what is the meaning of the dollar sign after a method name in vb.net

痞子三分冷 提交于 2019-11-26 19:57:30

问题


what is the meaning of the dollar sign after a method name in vb.net

like this:

Replace$("EG000000", "0", "")

回答1:


Old type notifier - see this

Some other old ones:

& -> Long
% -> Integer
# -> Double
! -> Single
@ -> Decimal
$ -> String

Still exist in VB.Net for the sake of backward compatibility...




回答2:


In "classic" VB, there were two versions of the built in-string functions. Let me use Left as an example:

  • Left(s, length) takes a variant as the first parameter and returns a variant.
  • Left$(s, length) takes a string as the first parameter and returns a string.

This distinction still exists in modern-day VBA.

I suspect that the reason behind this is that strings in VBA cannot be Null (note that Null <> ""). Thus, when dealing with nullable database fields, you had to use variant variables. Variant variables can take any value, including all of the integral values (strings, integers, ...) as well as some special values such as Null, Empty or Missing. The non-$ functions allowed you to use variants as input and get variants as output. For example, Left(Null, ...) returns Null.

In VB.NET, this distinction is no longer necessary: The non-$ functions do exactly the same as the $ functions, which are kept only for backwards compatibility with old code.




回答3:


What Heinzi said and to clear up the type character business

    Dim s$ = "FooBar" 'dim s as String = "FooBar"

    Dim r As String
    Stop

    r = Replace$(s, "Bar", "")
    '.Net equivalent
    r = s.Replace("Bar", "")


来源:https://stackoverflow.com/questions/8341524/what-is-the-meaning-of-the-dollar-sign-after-a-method-name-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!