Back to questions
JuniorTheoryCommon
What does the program print?
string s = "keyboard";
Console.WriteLine(s.Substring(3, 5));board
- Expecting
bo: the second argument ofSubstringis the length of the piece, not the index of its end, soSubstring(3, 5)takes five characters. - Expecting an exception: the piece may end at the last character, so a start of 3 and a length of 5 fit an 8-letter string exactly.
- What does
s.Substring(3)print for the same string? - What happens if the call is changed to
s.Substring(3, 6)?