在c#中修剪数组中的所有字符串

use*_*461 2 c# arrays string trim

我用这段代码来获取目录的内容:

string[] savefile = Directory.GetFiles(mcsdir, "*.bin");
comboBox1.Items.AddRange(savefile);
Run Code Online (Sandbox Code Playgroud)

它返回为

C:\Users\Henry\MCS\save1.bin
C:\Users\Henry\MCS\save2.bin
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它返回

save1.bin
save2.bin
Run Code Online (Sandbox Code Playgroud)

请注意,这个应用程序将被其他人使用,因此名称并不总是"亨利".谢谢.

Ry-*_*Ry- 6

我建议使用DirectoryInfo.GetFiles而不是LINQ:

FileInfo[] savefile = new DirectoryInfo(mcsdir).GetFiles("*.bin");
comboBox1.Items.AddRange(savefile.Select(x => x.Name).ToArray());
Run Code Online (Sandbox Code Playgroud)