How to use LINQ to return substring of FileInfo.Name

后端 未结 4 1131
遇见更好的自我
遇见更好的自我 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:29

    IList fileNameSubstringValues =
      (
        from 
          file in codeToGetFileListGoesHere
        select 
          file.Name.
            Substring(0, file.Name.Length - 
              (file.Name.Length - file.Name.IndexOf(".config.xml"))).ToList();
    

    Enjoy =)

提交回复
热议问题