trygetvalue

Windows Phone 8 Error with NavigationContext.QueryString.TryGetValue()

こ雲淡風輕ζ 提交于 2020-01-17 03:49:47
问题 I've run into an issue with passing parameters between pages. OnNavigatedTo is definitely being called but the if statement keeps returning false, when it should return true. Can anyone out there shoot me in the right direction? The following is on my main page: NavigationService.Navigate(new Uri("/Class_page.xaml?name=" + classes[0].name + "&code=" + classes[0].code + "&semester=" + classes[0].semester + "&index=" + index, UriKind.Relative)); The following is on my "Class_page": protected

How to call Dictionary<K, V>.TryGetValue() where K : Predicate<T>, V : enum

假装没事ソ 提交于 2019-12-08 22:10:30
I have Dictionary<Predicate<double>, SomeEnum> : var dic = new Dictionary<Predicate<double>, SomeEnum> { { (d) => d < 10, SomeEnum.Foo }, { (d) => d > 90, SomeEnum.Bar } }; I want to call TryGetValue(K, out V) against it like this: dic.TryGetValue(99) and receive SomeStruct.Bar But first param for TryGetValue() is Predicate<T> , not just T . How can I do what I want? I found only a dirty workaround: var kpv = dic.FirstOrDefault(p => p.Key(99)); if (kpv.Key != null) var result = kpv.Value; Are there other ways? Or how to implement my idea properly? - declare a key not as a constant but like a

Is there any implementation to Remove by Key and get the Value at the same time?

一世执手 提交于 2019-12-08 17:22:55
问题 I'm doing a performance critical program (little academic stuff) and I'm looking to optimize wherever possible (not like it proved "this is the" bottleneck). I have a custom dictionary structure (a wrapper around .NET Dictionary<,> ) and I would constantly Remove items at one stage (by the Key value). I need the Value of the removed items. Right now I have to do: T t; if !TryGet(key, out t) return false; Remove(key); That's two lookups. I would love this: public bool Remove(S key, out T value

How to call Dictionary<K, V>.TryGetValue() where K : Predicate<T>, V : enum

一曲冷凌霜 提交于 2019-12-08 06:02:15
问题 I have Dictionary<Predicate<double>, SomeEnum> : var dic = new Dictionary<Predicate<double>, SomeEnum> { { (d) => d < 10, SomeEnum.Foo }, { (d) => d > 90, SomeEnum.Bar } }; I want to call TryGetValue(K, out V) against it like this: dic.TryGetValue(99) and receive SomeStruct.Bar But first param for TryGetValue() is Predicate<T> , not just T . How can I do what I want? I found only a dirty workaround: var kpv = dic.FirstOrDefault(p => p.Key(99)); if (kpv.Key != null) var result = kpv.Value; Are