The C# 3.0 spec has the following code example in section 10.6.1.3 ‘Output parameters’:
using System; class Test { static void SplitPath(string path, out string dir, out string name) { int i = path.Length; while (i > 0) { char ch = path[i – 1]; if (ch == '\\' || ch == '/' || ch == ':') break; i--; } dir = path.Substring(0, i); name = path.Substring(i); } static void Main() { string dir, name; SplitPath('c:\\Windows\\System\\hello.txt', out dir, out name); Console.WriteLine(dir); Console.WriteLine(name); } }
I cannot get this code to compile in VS2005/C#2.0. Did the behavior of strings in C# 3.0 change so that a string can be referred as a char[] array without explicitly converting it (the statement ‘ch = path[i – 1]’)?
It is an invalid character ‘–’. Change ‘–’ to ‘-‘