string word = "hello"; char firstChar = word[0]; char lastChar = word[word.Length - 1]; Console.WriteLine($"{firstChar} {lastChar}");
Strings in C# are like arrays of characters. The first character is at index 0, so word[0] is 'h'. The last character is at index Length - 1, which is 4 here, so word[4] is 'o'.
Strings hold characters in order, like a list or array, which lets us access, search, and manipulate them. This makes strings a data structure.
string text = "data"; char c = text[4]; Console.WriteLine(c);
The string 'data' has length 4, so valid indices are 0 to 3. Accessing index 4 is out of range and throws IndexOutOfRangeException.
Option C loops backward through the string indices, building a new string with characters in reverse order.
Option C copies the string as is. Option C tries to call Reverse() on string which is invalid without conversion. Option C changes case, not order.
Because strings cannot be changed after creation, they can be shared safely without risk of one part altering the string and affecting others. This helps with memory efficiency and program safety.
