Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert list to dictionary
    primarykey
    data
    text
    <p>I have a list of these objects that I would like to convert to a dictionary:</p> <pre><code>public class Thing { public Guid ParentKey { get; set; } public int Position { get; set; } public bool Unconfigured { get; set; } public void Replace(Thing thing); } </code></pre> <p>I would like the key and value to be Thing objects where the ParentKey and Position are the same. The key object must have Unconfigured set to true and the value would be a sibling object that has the same ParentKey and Position but a false Unconfigured state. I'm trying to create a pairs of objects that have the same ParentKey, Position but have different Unconfigured states.</p> <p>Example:</p> <pre><code>var things = new List&lt;Thing&gt;(); things.Add(new Thing { ParentKey = new Guid("8a1211d2-f42b-4dd2-b6a3-7f4ab4a44a8d"), Position = 1, Unconfigured = true }); things.Add(new Thing { ParentKey = new Guid("8a1211d2-f42b-4dd2-b6a3-7f4ab4a44a8d"), Position = 1, Unconfigured = false }); things.Add(new Thing { ParentKey = new Guid("35f22dba-7789-49f4-8982-c9ea075175cc"), Position = 2, Unconfigured = false }); </code></pre> <p>I expect a dictionary with one item. The key for that item is the first thing object added and the value is the second thing object added.</p> <p>The intended use of this is to call the replace method:</p> <pre><code>foreach (var entry in things) { entry.Key.Replace(entry.Value); } </code></pre> <p>A dictionary may not be an appropriate object for this, I'm open to other suggestions.</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.
 

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