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

前端 未结 3 1872
南旧
南旧 2020-12-05 02:12

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

like this:

Replace$(\"EG000000\", \"0\", \"\")
相关标签:
3条回答
  • 2020-12-05 02:43

    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...

    0 讨论(0)
  • 2020-12-05 02:56

    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", "")
    
    0 讨论(0)
  • 2020-12-05 03:02

    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.

    0 讨论(0)
提交回复
热议问题