3
是否有可能在Linq中的lambda表達式的Select語句中引用當前對象的屬性?在lambda表達式中引用當前對象
實施例:
...
.Select(s => new {
Date = s.Date.ToString("yyyy-MM-dd"),
Time = s.Time.ToString("h':'m"),
DateTime = s.Date.ToString("yyyy/MM/dd") +"-"+ s.Time.ToString("h':'m"),
Temperature = s.Temperature,
Humidity = s.Humidity,
Device = s.Device.Name,
Message = s.Message
})
我想通過參考先前定義Date
和Time
性質的雙呼叫取代到ToString
功能。
這段代碼讓我想起了SML代碼! – Star
@Star:確實; LINQ與功能語言有很強的關聯。 – Douglas