Welcome to the C# Strings Quiz! In this quiz, you’ll test your knowledge of C# strings, one of the most fundamental aspects of programming in C#. You’ll encounter questions about creating, manipulating, and comparing strings, along with methods used to transform and work with string data. Whether it’s concatenating strings, accessing individual characters, or understanding string immutability, this quiz will challenge your understanding and reinforce key concepts.
2.
How can you declare a string in C# without initializing it?
3.
What is the result of the following code?
string myString = "Hello World";
Console.WriteLine(myString.Length);
4.
How do you access the second character in the string "Hello"?
5.
What error will the following code produce?
string myString = "Hello";
myString[0] = 'h';
6.
How can you convert a string to a character array in C#?
7.
Which of the following correctly concatenates two strings in C#?
8.
How can you compare two strings in a case-sensitive manner in C#?
9.
What will the following code output?
string myString1 = "HELLO";
string myString2 = "hello";
Console.WriteLine(string.Equals(myString1, myString2, StringComparison.OrdinalIgnoreCase));
10.
What does the string.ToUpper() method do?
11.
Which method splits a string into an array of substrings based on a delimiter?
12.
How can you remove leading and trailing spaces from a string in C#?
13.
Which method is used to replace all occurrences of a substring in a string?
14.
What will the following code output?
string myString = "hello";
string paddedString = myString.PadLeft(10, '*');
Console.WriteLine("[" + paddedString + "]");
15.
How does C# handle string immutability?