The problem is that your expectation is wrong.
so I can access such as pianist[0] == "Johann"
since pianist
is your original string, trying to access it with an index will result in chars
at this position in the string. (since a string is represented by a char[]
).
If you look at the documentation of the method Split() you will see that it returns a string[]
and not a string as you tried. You need first to catch this return value in an extra variable, then you can access it the way you planed:
string pianist = "Johann Sebastian Bach";
string [] returnedArray = pianist.Split(' ');
string johann = returnedArray[0];
string sabastian = returnedArray[1];
string bach = returnedArray[2];