你好,我是新來的LINQ和拉姆達Linq查詢,選擇一切從一個列出了與另一個列表
我有兩個列表
fl.LocalOpenFiles ...
List<string> f....
有一個屬性(字符串的字符串開頭財產),例如以指數0
fl.LocalOpenFiles[0].Path
我想選擇所有從第一清單fl.LocalOpenFiles
其中fl.LocalOpenFiles.Path
開始從字符串
我終於得到這個...
List<LocalOpenFile> lof = new List<LocalOpenFile>();
lof = fl.LocalOpenFiles.Join(
folders,
first => first.Path,
second => second,
(first, second) => first)
.ToList();
但它只是選擇符合要求first.Path == second
文件夾和我不能找到一個辦法讓我想這是一件好事會議這種「題庫」數據要求:
f[<any>] == fl.LocalOpenFiles[<any>].Path.Substring(0, f[<any>].Length)
另一個實施例...
List<string> f = new List<string>{ "abc", "def" };
List<LocalOpenFile> lof = new List<LocalOpenFile>{
new LocalOpenFile("abc"),
new LocalOpenFile("abcc"),
new LocalOpenFile("abdd"),
new LocalOpenFile("defxsldf"),)}
// Result should be
// abc
// abcc
// defxsldf
我希望我的理解的方式解釋吧:) 謝謝您的幫助
+1,任何肯定更緊湊的是,雖然變量的命名還有待改進。 –