java - Quote marks when concatenating string with a single character -


what kind of quote marks should choose single character when concatenate string?

string s1="string"; 

should use

string s2=s1+'c'; 

or

string s2=s1+"c"; 

?

you can use both! give try!

"why?" ask. magic here + operator.

when + used strings, automatically turns other operand string! that's why can used 'c', character literal. can used "c" because of course, "c" string literal.

not that, can add integers string:

string s2=s1+1; 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -