【发布时间】:2013-03-12 06:25:41
【问题描述】:
以下函数生成错误,“使用未分配的局部变量 'intLast'。我不确定自己做错了什么。
static string RemovePath(string strInput)
{
int intLast;
for (int i = 1; i < strInput.Length; i++)
{
if (strInput.Substring(i, 1) == @"\")
{
intLast = i;
}
}
string strOutput = strInput.Substring(strInput.Length - intLast);
return strOutput;
}
【问题讨论】:
-
不会只删除第一个路径部分,使循环变得多余吗?仅供参考,有实用功能,例如
System.IO.Path.GetFileName() -
System.IO.Path.GetFileName() 更容易!谢谢!