C# query

  • Thread starter Thread starter lovey dovey via .NET 247
  • Start date Start date
L

lovey dovey via .NET 247

(Type your message here)

--------------------------------
From: lovey dovey

Hi everyone,
I am new to C#.Can any one help me with the following.
What are the issues involved in String concatenation when ?&? is used, and when
?+? is used in C#?

Thanx in advance.
 
Hi lovey dovey

In VB.net there is no difference between using '&' and '+' for string concatenation. Behind the scenes both operators generate code for calling the method String.Concat. My guess is that '&' is allowed just to make 'old' VB coders happy

Regards, Jakob.
 
lovey dovey via .NET 247 said:
(Type your message here)

--------------------------------
From: lovey dovey

Hi everyone,
I am new to C#.Can any one help me with the following.
What are the issues involved in String concatenation when ?&? is used, and when
?+? is used in C#?

Thanx in advance.
As you're asking this question in the context of C#, are you aware that &
cannot be used for string concatenation in C#? You can use the & and +
operators in VB.NET as Jakob has told you, but not in C#.
 
While string-to-string concatenation bears little to no difference, it
should be noted the concatenation of different data types is most definitely
affected depending whether you use & or +.

For example, if you were to print the debug results of:
"4" + 5
and
"4" & 5
you will get different results (try it). The addition operator (as in VB6)
for a string tries to be a little smarter than your average bear. Often
doing what you don't want it to.

K.
In VB.net there is no difference between using '&' and '+' for string
concatenation. Behind the scenes both operators generate code for calling
the method String.Concat. My guess is that '&' is allowed just to make
'old' VB coders happy.
 
Back
Top