Bird
0
0

Which of the following is the correct syntax to concatenate two strings str1 and str2 in C#?

easy📝 Syntax Q12 of 15
C Sharp (C#) - Strings and StringBuilder
Which of the following is the correct syntax to concatenate two strings str1 and str2 in C#?
Astring result = str1 * str2;
Bstring result = str1 + str2;
Cstring result = str1 - str2;
Dstring result = str1 / str2;
Step-by-Step Solution
Solution:
  1. Step 1: Identify valid operators for string concatenation

    The + operator is used to join strings in C#. Other arithmetic operators like -, *, / are invalid for strings.
  2. Step 2: Confirm syntax correctness

    The statement string result = str1 + str2; correctly concatenates and assigns the result.
  3. Final Answer:

    string result = str1 + str2; -> Option B
  4. Quick Check:

    Use + for string join [OK]
Quick Trick: Use + to join strings, not arithmetic signs [OK]
Common Mistakes:
MISTAKES
  • Using - or * instead of + for strings
  • Missing semicolon at end
  • Trying to divide or multiply strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes