Cobold
Cobold

Reputation: 2613

Operator '&' cannot be applied to operands of type 'string' and 'string'

I'm trying the following code:

string text = "";
char c = 'd';
text += "abc" & c.ToString();

..but it returns an error 'Operator '&' cannot...' . It don't works even without ToString(). What's the problem converting char to string?

Upvotes: 1

Views: 12835

Answers (2)

Coincoin
Coincoin

Reputation: 28596

The string concatenation operator is a plus sign in C#, not an ampersand.

Upvotes: 2

Brandon
Brandon

Reputation: 69983

You don't use & for string concatentation in C#, you use +

string text = ""; 
char c = 'd'; 
text += "abc" + c;

Upvotes: 12

Related Questions