0
var myDictionary = new Dictionary<int, List<DateTimeOffset?>>
{
{1234, new List<DateTimeOffset?> {new DateTimeOffset(DateTime.Today), null, new DateTimeOffset(DateTime.Today)}},
{2134, new List<DateTimeOffset?> {null, new DateTimeOffset(DateTime.Today), new DateTimeOffset(DateTime.Today)}},
{2345, new List<DateTimeOffset?> {null, null, new DateTimeOffset(DateTime.Today)}},
{3451, new List<DateTimeOffset?> {new DateTimeOffset(DateTime.Today).AddDays(-1), null, new DateTimeOffset(DateTime.Today)}}
};
當我通過DateTimeOffset(DateTime.Today)進行搜索時,我只想選擇或提取鍵1234,2134和2345而不是最後一個3451,因爲不是這個鍵的所有值都等於搜索的datetimeoffset值DateTimeOffset(DateTime.Today)忽略空值。從詞典中提取鍵值中的所有值都等於搜索值
我需要這個請求一個linq查詢。這個查詢似乎這樣做,但如何提取字典的關鍵?
var mySearchResult = myDictionary.Values.Where(v1 => v1.All(d2 => d2.HasValue == false || d2.Value == new DateTimeOffset(DateTime.Today)));
任何幫助,非常感謝。