1
內進行計數,我有以下lambda表達式:跳過當添加「讓」元素不能lambda表達式
string queryToken = queryTokens.Last();
var result = from locationAddress in locations
let tokens = GetLetterTokens(locationAddress.Name)
let distance = (from token in tokens
where token.Contains(queryToken, StringComparison.OrdinalIgnoreCase)
select token.Length - queryToken.Length).Min()
orderby distance
select new
{
LocationAddress = locationAddress,
LocationDistance = distance,
};
這不要緊,它是寫的。有時在計算distance
時,沒有tokens
包含queryToken
,因此無法返回.Min()
。如何跳過這些情況?我不想將它們添加到result
變量中。
感謝隊友:)完美的作品! – Nickon