How to use LINQ to return substring of FileInfo.Name

后端 未结 4 1089
遇见更好的自我
遇见更好的自我 2021-01-19 21:47

I would like to convert the below \"foreach\" statement to a LINQ query that returns a substring of the file name into a list:

IList fileNameSu         


        
4条回答
  •  面向向阳花
    2021-01-19 22:31

    Try something like this:

    var fileList = files.Select(file =>
                                file.Name.Substring(0, file.Name.Length -
                                (file.Name.Length - file.Name.IndexOf(".config.xml"))))
                         .ToList();
    

提交回复
热议问题