Vidyalelo
C# Programming · Q46

Arrays and Strings in C Sharp

Programming · C# Programming · question 46

Q46

Which of these methods of class String is used to extract all the characters from a String object?

A.
CHARAT()
B.
Remove()
C.
charAt()
D.
Replace()
E.
ToCharArray()
Answer

Answer: Option E

Solution

Answer: Option E
Solution:
The question asks which method of the String class in C# is used to extract all characters from a string.

The correct method is ToCharArray(), which converts the entire string into an array of characters.

Syntax:
char[] ToCharArray()

This method returns a character array containing all the characters of the string in the same sequence.

Example:
string myString = "Hello";
char[] chars = myString.ToCharArray();
After execution, chars will contain: ['H', 'e', 'l', 'l', 'o'].

Option A: CHARAT() – Invalid in C#. It belongs to Java and has incorrect casing.

Option B: Remove() – Used to delete a portion of a string, not to extract characters.

Option C: charAt() – Also a Java method, not part of C#.

Option D: Replace() – Used to replace characters or substrings, not to extract them.

Therefore, the correct and updated answer is Option E: ToCharArray().