日期:2014-05-17  浏览次数:20768 次

菜鸟求解问题
有这么几个文件  path1  path2  path3  path4  path5,如果path1存在则用path1,否则用path2,如果path2也不纯在则用path3,这样依次选着。
------解决方案--------------------

            if (!System.IO.File.Exists(path1))
            {
            }
            else if (!System.IO.File.Exists(path2))
            {
            }
......

------解决方案--------------------

string fileResult =string.Empty;
if(File.Exists(path1))
{
    fileResult =path1;
}
else if(File.Exists(path2))
{
    fileResult = path2;
}
else if(File.Exists(path3))
{
    fileResult = path3;
}
else if(File.Exists(path4))
{
    fileResult = path4;
}
else if(File.Exists(path5))
{
    fileResult = path5;
}
return fileResult;


------解决方案--------------------
引用:
C# code?12345678910111213141516171819202122string fileResult =string.Empty;if(File.Exists(path1)){    fileResult =path1;}else if(File.Exists(path2)){    fileResult = path2;}else if(File.E……
 这样写就可以
------解决方案--------------------
string[] paths = new string[] { path1,path2,path3,path4,path5 };
string path = "";
for (int i = 0; i < paths.Length ; i++)
{
   if (System.IO.File.Exists(paths[i]))
  {
     path = paths[i];
     break;
 }
}
使用PATH即可