Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple of things wrong here:</p> <p><code>Predicate&lt;double&gt;</code> is not an appropriate type to use as a <code>TKey</code>. The key for a dictionary is supposed to <em>identify</em> a value, not calculate a value.</p> <p>This wouldn't make any sense using lambdas either. Because they are anonymous, you wouldn't get any equivalence, and won't be able use a dictionary. </p> <p>See this code sample for an illustration:</p> <pre><code>Predicate&lt;double&gt; fn_1 = d =&gt; d == 34.0d; Predicate&lt;double&gt; fn_2 = d =&gt; d == 34.0d; // Note: There are not equal if (fn_1 == fn_2) Console.WriteLine("These are Equal?"); </code></pre> <p>If anything, you could use a list of delegates and execute each one to find the ones that match, but at that point you must expect multiple results. If you only want to get a single result, then you have to consider which <em>order</em> the predicates are stored within your list.</p> <p>Don't misuse <code>KeyValuePair</code> as a hack for not having <code>Tuple&lt;T1,T2&gt;</code>. It would be fairly easy to create a class that has both a Predicate and a SomeStruct. Look:</p> <pre><code>public class MySegment { public Predicate&lt;double&gt; Predicate {get;set;} public SomeStruct Result {get;set;} } </code></pre> <p>To go through a sequence of predicates, and find the matching ones would look like this:</p> <pre><code>... List&lt;MySegment&gt; list = new List&lt;MySegment&gt;(); ... list.Add(new MySegment { Predicate = d =&gt; d &lt; 10, Result = SomeStruct.Foo }); list.Add(new MySegment { Predicate = d =&gt; d &gt; 90, Result = SomeStruct.Bar }); ... public IEnumerable&lt;SomeStruct&gt; GetResults(double input) { foreach (var item in list) if (item.Predicate(input)) yield return item.Result; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload