Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否使用switch语句创建文件目录?_C#_Unity3d_Io_Switch Statement - Fatal编程技术网

C# 是否使用switch语句创建文件目录?

C# 是否使用switch语句创建文件目录?,c#,unity3d,io,switch-statement,C#,Unity3d,Io,Switch Statement,我正在创建一个将要安装在许多设备上的应用程序,我希望尽可能在每个设备的本地磁盘上自动设置文件系统。使用switch语句有没有比使用几十个if语句更简化的方法呢 if (System.IO.Directory.Exists(arctopithecusGalleryPath) == false) { System.IO.Directory.CreateDirectory(arctopithecusGalleryPath); } 为它创建一个方法怎么样: if (

我正在创建一个将要安装在许多设备上的应用程序,我希望尽可能在每个设备的本地磁盘上自动设置文件系统。使用switch语句有没有比使用几十个if语句更简化的方法呢

if (System.IO.Directory.Exists(arctopithecusGalleryPath) == false)
{
    System.IO.Directory.CreateDirectory(arctopithecusGalleryPath);              
}

为它创建一个方法怎么样:

if (System.IO.Directory.Exists(arctopithecusGalleryPath) == false)
{
    System.IO.Directory.CreateDirectory(arctopithecusGalleryPath);              
}
public void CreateIfNotExists(string path)
{
    if (System.IO.Directory.Exists(path) == false)
    {
        System.IO.Directory.CreateDirectory(path);              
    }
}
然后在代码中使用它,如下所示:

if (System.IO.Directory.Exists(arctopithecusGalleryPath) == false)
{
    System.IO.Directory.CreateDirectory(arctopithecusGalleryPath);              
}
CreateIfNotExists(arctopithecusGalleryPath);
或者,如果您有多个目录,可以将它们添加到列表中,并在foreach语句中调用此方法:

if (System.IO.Directory.Exists(arctopithecusGalleryPath) == false)
{
    System.IO.Directory.CreateDirectory(arctopithecusGalleryPath);              
}
List<string> folders = new List<string>();
folders.Add("a folder to create");
// add more folders
foreach(var folder in folders)
{
    CreateIfNotExists(folder);        
}
List folders=新建列表();
文件夹。添加(“要创建的文件夹”);
//添加更多文件夹
foreach(文件夹中的var文件夹)
{
CreateIfNotExists(文件夹);
}

为其创建一个方法如何:

if (System.IO.Directory.Exists(arctopithecusGalleryPath) == false)
{
    System.IO.Directory.CreateDirectory(arctopithecusGalleryPath);              
}
public void CreateIfNotExists(string path)
{
    if (System.IO.Directory.Exists(path) == false)
    {
        System.IO.Directory.CreateDirectory(path);              
    }
}
然后在代码中使用它,如下所示:

if (System.IO.Directory.Exists(arctopithecusGalleryPath) == false)
{
    System.IO.Directory.CreateDirectory(arctopithecusGalleryPath);              
}
CreateIfNotExists(arctopithecusGalleryPath);
或者,如果您有多个目录,可以将它们添加到列表中,并在foreach语句中调用此方法:

if (System.IO.Directory.Exists(arctopithecusGalleryPath) == false)
{
    System.IO.Directory.CreateDirectory(arctopithecusGalleryPath);              
}
List<string> folders = new List<string>();
folders.Add("a folder to create");
// add more folders
foreach(var folder in folders)
{
    CreateIfNotExists(folder);        
}
List folders=新建列表();
文件夹。添加(“要创建的文件夹”);
//添加更多文件夹
foreach(文件夹中的var文件夹)
{
CreateIfNotExists(文件夹);
}

将变量存储在数组中并循环它们以避免多个IFs

if (System.IO.Directory.Exists(arctopithecusGalleryPath) == false)
{
    System.IO.Directory.CreateDirectory(arctopithecusGalleryPath);              
}
string[] arr1 = new string[] { arctopithecusGalleryPath, arctopithecusGalleryPath1, arctopithecusGalleryPath3 };

for (int i = 0; i < arr1.Length; i++)
{
       if (System.IO.Directory.Exists(array[i]) == false){
       System.IO.Directory.CreateDirectory(array[i]);              
}
string[]arr1=新字符串[]{arctopithecusGalleryPath,arctopithecusGalleryPath1,arctopithecusGalleryPath3};
for(int i=0;i
将变量存储在数组中并循环它们以避免多个IFs

if (System.IO.Directory.Exists(arctopithecusGalleryPath) == false)
{
    System.IO.Directory.CreateDirectory(arctopithecusGalleryPath);              
}
string[] arr1 = new string[] { arctopithecusGalleryPath, arctopithecusGalleryPath1, arctopithecusGalleryPath3 };

for (int i = 0; i < arr1.Length; i++)
{
       if (System.IO.Directory.Exists(array[i]) == false){
       System.IO.Directory.CreateDirectory(array[i]);              
}
string[]arr1=新字符串[]{arctopithecusGalleryPath,arctopithecusGalleryPath1,arctopithecusGalleryPath3};
for(int i=0;i