Skip to main content
 首页 » 编程设计

c#之如何将 ListSystem.IO.FileInfo> 的类型转换为 Liststring>

2024年02月23日14davidwang456

我需要将这种类型的列表转换为字符串列表:

var fileName = (new DirectoryInfo(filePath)).GetFiles(".", SearchOption.AllDirectories).Where(a => Regex.IsMatch(a.Name, "^[^*]*" + logSelected + ".jpg$")).ToList(); 

有人知道吗?

请您参考如下方法:

var fileName = (new DirectoryInfo(filePath)) 
.GetFiles(".", SearchOption.AllDirectories) 
.Where(a => Regex.IsMatch(a.Name, "^[^*]*" + logSelected + ".jpg$")) 
.Select(a => a.Name) 
.ToList(); 

或者在 Select 方法中为您需要的属性更改 a.Name。