1

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?

2
  • Yes :) In VB all conversions from data types to data types are much simpler, so I found it pretty hard to get these conversions right in C#. Commented Jun 10, 2011 at 9:18
  • Of course from my perspective conversions in VB are much harder. :-) Commented Jun 10, 2011 at 14:17

2 Answers 2

12

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

string text = ""; 
char c = 'd'; 
text += "abc" + c;
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.