ExamVeda
Login
Home
Arrays and Strings in C Sharp
?

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

Answer & Solution
Correct Answer: Option E
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().
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Mohammad Abdul
Mohammad Abdul 1 year ago
can anyone explain how this is possible?