Bird
0
0

Which of the following is a valid way to create an empty string in C#?

easy🧠 Conceptual Q1 of 15
C Sharp (C#) - Strings and StringBuilder
Which of the following is a valid way to create an empty string in C#?
Astring s = "";
Bstring s = null;
Cstring s = ' ';
Dstring s = new String();
Step-by-Step Solution
Solution:
  1. Step 1: Understand empty string creation

    An empty string is a string with zero characters, represented by double quotes "".
  2. Step 2: Evaluate each option

    string s = ""; correctly assigns an empty string. string s = null; assigns null, not an empty string. string s = ' '; uses single quotes which are for chars, not strings. string s = new String(); is invalid because String() constructor requires parameters.
  3. Final Answer:

    string s = ""; -> Option A
  4. Quick Check:

    Empty string = "" [OK]
Quick Trick: Use double quotes "" for empty strings in C# [OK]
Common Mistakes:
MISTAKES
  • Using single quotes for strings
  • Confusing null with empty string
  • Trying to use String() constructor without parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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