VB.NET指定字符串值----String1=String1+;String2

VB.NET指定字符串值----String1=String1+;String2,vb.net,string,vb6,Vb.net,String,Vb6,在VB6中,您可以将字符串的值重新分配给字符串本身以及其他字符串值,例如: str_Duplications_Line = str_Duplications_Line & pRow_Prime.Value(i_FieldNum) 现在,intellisense没有把它当作错误,编译器也没有抱怨,但当它运行时,它会在该行以及其他多行上爆炸,例如: str_Duplications_Line = str_Duplications_Line & "," str_Duplicatio

在VB6中,您可以将字符串的值重新分配给字符串本身以及其他字符串值,例如:

str_Duplications_Line = str_Duplications_Line & pRow_Prime.Value(i_FieldNum)
现在,intellisense没有把它当作错误,编译器也没有抱怨,但当它运行时,它会在该行以及其他多行上爆炸,例如:

str_Duplications_Line = str_Duplications_Line & ","

str_Duplications_AllFields = str_Duplications_AllFields + str_Duplications_Line + vbCrLf

知道为什么会发生这种情况吗?我该如何解决?或者至少,在VB.NET中模拟相同的东西?

确保您没有尝试将空值连接到字符串

确保您没有尝试将空值连接到字符串

这里是
&
+
之间的区别

"abc" + "def" = "abcdef"
"abc" & "def" = "abcdef"
"111" + "222" = "111222"
"111" & "222" = "111222"
"111" & 222 = "111222"
"111" + 222 = 333
"abc" + 222 = conversion error

如果任何一个操作数为空,则可能会出现错误。

这里是
&
+
之间的区别

"abc" + "def" = "abcdef"
"abc" & "def" = "abcdef"
"111" + "222" = "111222"
"111" & "222" = "111222"
"111" & 222 = "111222"
"111" + 222 = 333
"abc" + 222 = conversion error

如果任何一个操作数为空,则可能会出现错误。

“爆炸”?有错误吗?错误通常包含关于出错原因的有用信息。
+
&
运算符都可以用来连接字符串。有些关联:你所说的“轰炸”是什么意思?你犯了什么错误?“炸弹爆炸”?有错误吗?错误通常包含关于出错原因的有用信息。
+
&
运算符都可以用来连接字符串。有些关联:你所说的“轰炸”是什么意思?你得到了什么错误?我会做一个if-then语句,以确保它不会分配空值谢谢!但是在VB中将null连接到字符串难道不合法吗?AFAICR null被视为空字符串“”,我将执行if-then语句以确保它不会分配null谢谢!但是在VB中将null连接到字符串难道不合法吗?如果您对
“111”+222
有严格的选项,
“abc”+222
将不会编译AFAICR null,如果您对
“111”+222
有严格的选项,
“abc”+222
将不会编译AFAICR null