輸出參數(shù)的使用
public 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 == '\\') break;
i--;
}
dir = path.Substring(0, i);
name = path.Substring(i);
}
static void Main()
{
string dir, name; //變量作為輸出參數(shù)無須明確賦值
SplitPath("c:\\Windows\\System\\hello.txt", out dir, out name);
Console.WriteLine(dir);
Console.WriteLine(name);
}
}
點擊加載更多評論>>