C Sharp Strings Questions and Answers
Practice ModeShowing 10 of 32 questions
Q11
Which of the following statements are correct about the String Class in C#.NET?
Two strings can be concatenated by using an expression of the form s3 = s1 + s2;
String is a primitive in C#.NET.
A string built using StringBuilder Class is Mutable.
A string built using String Class is Immutable.
Two strings can be concatenated by using an expression of the form s3 = s1&s2;
Answer: Option C
Q12
Which of the following statements are correct?
1. String is a value type.
2. String literals can contain any character literal including escape sequences.
3. The equality operators are defined to compare the values of string objects as well as references.
4. Attempting to access a character that is outside the bounds of the string results in an IndexOutOfRangeException.
5. The contents of a string object can be changed after the object is created.
Answer: Option C
Q13
Which method is used to convert a string to uppercase in C#?
Answer: Option A
Explanation: ToUpper() method converts all characters in a string to uppercase.
Q14
What property of the String class returns the number of characters in the string?
Answer: Option A
Explanation: The Length property returns the total number of characters in the string.
Q15
Which method is used to check if a string contains a specified substring?
Answer: Option A
Explanation: Contains() method returns true if the substring is found in the string.
Q16
What does the String.Compare() method return when two strings are equal?
Answer: Option A
Explanation: String.Compare returns 0 when strings are equal, positive when first is greater, negative when first is smaller.
Q17
Which method removes all leading and trailing white-space characters from a string?
Answer: Option A
Explanation: Trim() method removes spaces from both beginning and end of a string.
Q18
How do you concatenate two strings in C#?
Answer: Option A
Explanation: Plus operator (+) is commonly used for string concatenation in C#.
Q19
Which method splits a string into substrings based on specified delimiters?
Answer: Option A
Explanation: Split() method divides a string into an array of substrings using given separators.
Q20
What is the result of "Hello".Substring(1, 3)?
Answer: Option A
Explanation: Substring(startIndex, length) extracts characters from startIndex for specified length.