Concat strings by & and + in VB.Net

后端 未结 8 952
萌比男神i
萌比男神i 2020-12-16 10:53

Is there any difference between & and + operators while concatenating string? if yes, then what is difference? And if No, then why below code generating exception?

8条回答
  •  不知归路
    2020-12-16 11:28

    From a former string concatenater (sp?) you should really consider using String.Format instead of concatenation.

        Dim s1 As String
        Dim i As Integer
        s1 = "Hello"
        i = 1
        String.Format("{0} {1}", s1, i)
    

    It makes things a lot easier to read and maintain and I believe makes your code look more professional. See: code better – use string.format. Although not everyone agrees When is it better to use String.Format vs string concatenation?

提交回复
热议问题