C# 将数组中的文件名更改为lower()时,是否需要在将文件名更改为lower()后重新填充数组?

C# 将数组中的文件名更改为lower()时,是否需要在将文件名更改为lower()后重新填充数组?,c#,arrays,path,C#,Arrays,Path,在检查文件夹中的每个文件并确保扩展名为小写后,是否需要像上面一样使用小写的大小写名称重新填充数组(在本例中为原始文件)?由GetExtension()方法在.Net中是区分大小写的使用适当的重载,您可以停止关心大小写 if (fbFolderBrowser.ShowDialog() == DialogResult.OK) { LastSelectedFolder = fbFolderBrowser.SelectedPath;

在检查文件夹中的每个文件并确保扩展名为小写后,是否需要像上面一样使用小写的大小写名称重新填充数组(在本例中为原始文件)?

GetExtension
()方法在.Net中是区分大小写的

使用适当的重载,您可以停止关心大小写

if (fbFolderBrowser.ShowDialog() == DialogResult.OK)
            {
                LastSelectedFolder = fbFolderBrowser.SelectedPath;

                originalFiles = Directory.GetFiles(fbFolderBrowser.SelectedPath).Where(file => !file.EndsWith(".db")).ToArray();

                //lower casing the extensions here.
                foreach (string file in originalFiles)
                {
                    File.Move(file, Path.ChangeExtension(file, Path.GetExtension(file).ToLower()));
                }

                //after im done changing the files to lower case, do I need to repopulate the array with the lowered case file names?
                originalFiles = Directory.GetFiles(fbFolderBrowser.SelectedPath).Where(file => !file.EndsWith(".db")).ToArray();
            }
如果您的意思是“原始字符串对象将在此处更改”:


然后答案是“否”,原始文件数组中的每个项都将保持不变。

您最好使用忽略大小写的字符串比较ahhh,我不知道有一个忽略大小写的函数。我想这就行了。谢谢另外,需要8分钟来接受您的答案。:)
// for example
file.EndsWith(".db", StringComparison.OrdinalIgnoreCase)
File.Move(file, Path.ChangeExtension(file, Path.GetExtension(file).ToLower()));