vb.net - Predicate to use Find on a List of Tuple -


i have dictionary:

public tbldic new dictionary(of string, list(of tuple(of date, date, decimal))) 

i need retrieve 3rd item (decimal) of tuple having highest date on 2nd item.

i able retrieve 3rd item knowing date wasn't able retrieve highest date:

dim lastdate date = date.parseexact("31/12/2016", "dd/mm/yyyy",                                        new cultureinfo("it-it"), datetimestyles.none) dim lastrate2 decimal = tbldic("legali").find(function(d) d.item2 = lastdate).item3 

another way put tuple datatable , use datatable.select retrieve decimal field way:

dim lastrate decimal = dt_rates.select("enddate=max(enddate)")(0).field(of decimal)("rate") 

so, questions are:
1) possible use list.find without knowing last date?
2) best practice between list.find , datatable.select?

you could use find... maybe? think simple enough without it.

dim lastrate decimal = tbldic.     selectmany(function(k) k.value).     orderbydescending(function(k) k.item2).     first().item3 

selectmany() takes many sequences , flattens them 1 sequence. sequences in case values of dictionary, list(of tuple(of date, date, decimal))

orderbydescending() orders flattened sequence predicate, returns date of tuple(of date, date, decimal). orders all tuple(of date, date, decimal) across lists since flattened

first() takes first tuple(of date, date, decimal) after ordered date descending

item3 returns decimal of tuple(of date, date, decimal)


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -