該C# 3.0 spec具有第10.6.1.3下面的代碼示例「輸出參數」:字符串作爲C#3.0中的char []數組?
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);
}
}
我不能得到這個代碼在VS2005/C#2.0編譯。 C#3.0中的字符串行爲是否發生了變化,以便可以將字符串引用爲char []數組而不顯式轉換它(語句「ch = path [i-1]」)?
吉姆 - 請注意您的回覆如何與您回覆的答案不同步?您需要將回復添加爲評論,而不是添加新答案,以確保對話流動。 你還沒有評論的聲望呢,我明白了,但你知道...... – 2008-12-03 18:38:13