的子我想下面「的foreach」語句轉換爲LINQ查詢,返回的文件名的字符串到一個列表:如何使用LINQ返回FileInfo.Name
IList<string> fileNameSubstringValues = new List<string>();
//Find all assemblies with mapping files.
ICollection<FileInfo> files = codeToGetFileListGoesHere;
//Parse the file name to get the assembly name.
foreach (FileInfo file in files)
{
string fileName = file.Name.Substring(0, file.Name.Length - (file.Name.Length - file.Name.IndexOf(".config.xml")));
fileNameSubstringValues.Add(fileName);
}
結束結果將類似於下面的內容:
IList<string> fileNameSubstringValues = files.LINQ-QUERY-HERE;
這裏沒有查詢,只是從A []到B []的轉換。 – 2009-01-06 21:24:55