C#.NET strings — select the correct statement about strings.

C# Programming Strings Difficulty: Easy
Choose an option
  • A
    A String is mutable because it can be modified once it has been created.
  • B
    Methods of the String class can be used to modify the string.
  • C
    A number CANNOT be represented in the form of a String.
  • D
    A String has a zero-based index.
  • E
    The System.Array class is used to represent a string.

Answer

Correct Answer: A String has a zero-based index.

Explanation

Introduction / Context:This item focuses on core properties of C# strings: immutability, indexing, and representation.

Given Data / Assumptions:

  • We are evaluating stand-alone statements regarding strings.

Concept / Approach:In C#, string is immutable and zero-indexed. You can create new strings via methods, but existing instances do not change in place.

Step-by-Step Solution:

Immutability: statements (a) and (b) are false; methods return new strings instead of modifying the original.Numeric text: (c) is false; any number can be represented as text (e.g., "123").Indexing: (d) is true — string indexer uses zero-based positions.Representation: (e) is false — strings are System.String, not System.Array, though you can get a char[] copy.

Verification / Alternative check:Observe that s.Replace("a","b") leaves s unchanged and returns a new string.

Why Other Options Are Wrong:They contradict immutability or conflate arrays with strings.

Common Pitfalls:Assuming string behaves like a mutable character buffer; use StringBuilder for that.

Final Answer:A String has a zero-based index.

Discussion & Comments
No comments yet. Be the first to comment!
Join Discussion