C Sharp Strings Questions and Answers
Practice ModeShowing 10 of 32 questions
Q21
Which method replaces all occurrences of a specified character in a string?
Answer: Option A
Explanation: Replace() method substitutes all instances of old character with new character.
Q22
What does String.IsNullOrEmpty() check for?
Answer: Option A
Explanation: Checks if string is null or has zero length (empty string).
Q23
Which method converts a string to lowercase?
Answer: Option A
Explanation: ToLower() method converts all characters in a string to lowercase.
Q24
What is the purpose of String.Format() method?
Answer: Option A
Explanation: String.Format formats strings by replacing format items with specified values.
Q25
Which method checks if a string starts with a specified substring?
Answer: Option A
Explanation: StartsWith() returns true if string begins with the specified value.
Q26
What does "Hello".IndexOf("l") return?
Answer: Option A
Explanation: IndexOf returns the zero-based index of first occurrence of specified character.
Q27
Which method creates a new string by repeating a character multiple times?
Answer: Option A
Explanation: String constructor can create string by repeating character specified times.
Q28
What is string interpolation in C#?
Answer: Option A
Explanation: String interpolation uses $ prefix to embed expressions directly in string literals.
Q29
Which method removes a specified number of characters from a string?
Answer: Option A
Explanation: Remove() deletes characters from specified position to end or for given count.
Q30
What is the difference between String and StringBuilder?
Answer: Option A
Explanation: String is immutable while StringBuilder is mutable and more efficient for multiple modifications.