Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Matt's answer, getting the keys first, separately is the right way to go. Yes, there'll be some redundancy - but it will work. I'd take a working program which is easy to debug and maintain over an efficient program which either won't work or is hard to maintain any day. </p> <p>Don't forget that if you make <code>MovieUser</code> a reference type, the array will only be the size of as many references as you've got users - that's pretty small. A million users will only take up 4MB or 8MB on x64. How many users have you really got?</p> <p>Your code should therefore be something like:</p> <pre><code>IEnumerable&lt;MovieUser&gt; users = RetrieveUsers(); IDictionary&lt;MovieUser, float&gt; questions = new Dictionary&lt;MovieUser, float&gt;(); foreach (MovieUser user in users) { questions[user] = RetrieveGuess(user); } </code></pre> <p>If you're using .NET 3.5 (and can therefore use LINQ), it's even easier:</p> <pre><code>IDictionary&lt;MovieUser, float&gt; questions = RetrieveUsers.ToDictionary(user =&gt; user, user =&gt; RetrieveGuess(user)); </code></pre> <p>Note that if <code>RetrieveUsers()</code> can stream the list of users from its source (e.g. a file) then it will be efficient anyway, as you never need to know about more than one of them at a time while you're populating the dictionary.</p> <p>A few comments on the rest of your code:</p> <ul> <li>Code conventions matter. Capitalise the names of your types and methods to fit in with other .NET code.</li> <li>You're not calling <code>Dispose</code> on the <code>IEnumerator&lt;T&gt;</code> produced by the call to <code>GetEnumerator</code>. If you just use <code>foreach</code> your code will be simpler <em>and</em> safer.</li> <li><code>MovieUser</code> should almost certainly be a class. Do you have a genuinely good reason for making it a struct?</li> </ul>
    singulars
    1. This table or related slice is empty.
    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