4.5. Chapter Review Questions¶

1. What is printed by this fragment?

string s = "question";
Console.WriteLine(s.Length);
Console.WriteLine(s[2]);
Console.WriteLine(s.Substring(2, 3));
Console.WriteLine(s.Substring(3));
Console.WriteLine(s.IndexOf("ti"));
Console.WriteLine(s.IndexOf("to"));
int j = s.IndexOf("u"), k = s.IndexOf("o");
Console.WriteLine("{0} {1} {2}", j, k, s.Substring(j, k-j));

2. What is printed by this fragment?

string s = "Word";
s.ToUpper();
Console.WriteLine(s);

3. What is printed by this fragment?

string a = "hi", b = a.ToUpper();
Console.WriteLine(a+b);

4. Are strings mutable or immutable: which?

5. What is the distinction syntactically between the use of a method and a property?

6. Suppose we have a string s. Is this expression legal, or what should it be?

s.Length()