Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This cannot be done using a Dictionary, because it relies on hash values to quickly determine where to look for a particular key.</p> <p>As you've discovered, you can invoke the predicates directly, but that will require O(n) functions to be called, which is no better than using a List, or even a big if/then/else statement. </p> <p>If your collection of potential predicates is too long for this to be an option, you'll need to create your own data structure to satisfy your purposes. If you're only planning to define values based on integer ranges, this shouldn't be difficult, but it could get out of hand if your predicates get more complex.</p> <p>On a side note, the F# language, which has built-in support for this sort of definition using <a href="http://msdn.microsoft.com/en-us/library/dd233242.aspx" rel="nofollow">Match Expressions</a>. I don't know how it goes about compiling the branches, but I assume it's fairly smart about it.</p> <p><strong>Edit</strong></p> <p>Here's an example of using a Match Expression in F# for something like this:</p> <pre><code>// Define the "choose" function let choose value = match value with | v when v &lt; 10 -&gt; 1 | v when v &gt; 90 -&gt; 2 | _ -&gt; 0 // Test the "choose" function let choice1 = choose 5 let choice2 = choose 15 let choice3 = choose 95 </code></pre> <p>The code above yields the following values:</p> <pre><code>choice1 = 1 choice2 = 0 choice3 = 2 </code></pre> <p>I've never actually worked with F# before, so you'll have to look around for how to use a function from F# in a C# program.</p>
    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. 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.
 

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