我可以用Zip函式連接兩個串列中的元素;來自file1的line1與file2的line1,等等。
var res = line1.Zip(lines2, (x, y) => $"{x} {y}");
有什么方法可以在查詢運算式中進行嗎?
var res = from E1 in lines1
where !string.IsNullOrWhiteSpace(e1)
from e2 in lines2
where !string.IsNullOrWhiteSpace(e2)
select $"{e1} {e2}"/span>。
這是將list1的每一行與list2的每一行連接起來,這不是我所需要的。
uj5u.com熱心網友回復:
不幸的是,查詢語法并不支持所有通過方法語法提供的東西(例如:Zip()方法、自寫的擴展方法或第三方庫,如MoreLinq)。
由于這一限制,用戶不可能在C#中獲得這一功能。相反,微軟作為該語言的所有者不得不實作這樣的功能,就像它所描述的那樣這里.
。uj5u.com熱心網友回復:
如果你很努力地瞇起眼睛,那么這就接近了:
IEnumerable<string> filtered1 =
from e1 in lines1
where !string.IsNullOrWhiteSpace(e1)
select e1;
IEnumerable<string> filtered2 =
from e2 in lines2
where !string.IsNullOrWhiteSpace(e2)
select e2;
IEnumerable<string> res =
from x in filtered1.Zip(filtered2, (e1, e2) => (e1, e2)
select $"{x.e1} {x.e2}"/span>。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/310059.html
標籤:
下一篇:獲取html屬性值
