1. How do you concatenate strings in C#?
Answer:
Explanation:
In C#, strings are commonly concatenated using the '+' operator.
2. What method is used to compare two strings for equality in C#?
Answer:
Explanation:
The equals() method is used to compare two strings for equality in C#.
3. Which method in the String class returns the length of a string in C#?
Answer:
Explanation:
The Length property of the String class is used to get the length of a string in C#.
4. How can you convert a string to uppercase in C#?
Answer:
Explanation:
The ToUpper() method is used to convert a string to uppercase in C#.
5. What is the output of the following code in C#?
Answer:
Explanation:
The Substring(7) method returns a new string starting from the 7th index of the original string.
6. What is the character used to denote a verbatim string in C#?
Answer:
Explanation:
In C#, the '@' character is used before a string literal to denote a verbatim string.
7. How do you split a string on specific characters in C#?
Answer:
Explanation:
The Split() method is used to split a string into an array of substrings based on specific characters.
8. What does the Trim() method do in C#?
Answer:
Explanation:
The Trim() method is used to remove all leading and trailing white-space characters from a string.
9. How do you determine if a string starts with a specific substring in C#?
Answer:
Explanation:
The StartsWith() method is used to check if a string starts with a specific substring.
10. What is the result of string concatenation using the following code in C#?
Answer:
Explanation:
The '+' operator is used to concatenate strings with a space in between.
11. How do you find the position of a substring within a string in C#?
Answer:
Explanation:
The IndexOf() method is used to find the position of a substring within a string.
12. Which method is used to replace a specified substring with another substring in a string in C#?
Answer:
Explanation:
The Replace() method is used to replace all occurrences of a specified substring with another substring in a string.
13. What is the output of the following code in C#?
Answer:
Explanation:
String indexing in C# is zero-based, so text[2] refers to the third character, which is 'h'.
14. How do you convert a string to a number in C#?
Answer:
Explanation:
Both int.Parse() and Convert.ToInt32() methods can be used to convert a string to a number.
15. What does the IsNullOrEmpty method do in C#?
Answer:
Explanation:
The IsNullOrEmpty method checks whether a string is null or its length is zero.
16. How do you format a string in C# using placeholders?
Answer:
Explanation:
Both the String.Format() method and string interpolation can be used to format strings using placeholders in C#.
17. What is the escape sequence used for a new line in C#?
Answer:
Explanation:
The '\n' escape sequence is used to represent a new line in C#.
18. How can you check if a string contains a specific substring in C#?
Answer:
Explanation:
The Contains() method is used to check if a string contains a specific substring.