Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem transforming dictionary with Linq
    primarykey
    data
    text
    <p>I've got a dictionary laid out like so:</p> <pre><code>Dictionary&lt;string, List&lt;Series&gt;&gt; example = new Dictionary&lt;string, List&lt;Series&gt;&gt;(); example.Add("Meter1",new List&lt;Series&gt;(){ new Series{ name="Usage", data = new double[] {1,2,3}}, new Series{ name = "Demand", data= new double[]{4,5,6}}}); example.Add("Meter2", new List&lt;Series&gt;(){ new Series{ name="Usage", data = new double[] {1,2,3}}, new Series{ name = "Demand", data= new double[]{4,5,6}}}); </code></pre> <p>What I need is:</p> <pre><code> Dictionary&lt;string, List&lt;Series&gt;&gt; exampleResult = new Dictionary&lt;string, List&lt;Series&gt;&gt;(); exampleResult.Add("Usage", new List&lt;Series&gt;(){ new Series{ name="Meter1", data = new double[] {1,2,3}}, new Series{ name = "Meter2", data= new double[]{1,2,3}}}); exampleResult.Add("Demand", new List&lt;Series&gt;(){ new Series{ name="Meter1", data = new double[] {4,5,6}}, new Series{ name = "Meter2", data= new double[]{4,5,6}}}); </code></pre> <p>That is, the dictionary projected "sideways", with the name of each Series as the key in the new dictionary, with the key of the old dictionary used as the name of the series.</p> <p>Here's the series class...</p> <pre><code>public class Series { public string name { get; set; } public double[] data { get; set; } } </code></pre> <p>Sorry if I am not expressing this problem clearly, please ask any questions you'd like, and thanks in advance for any help...</p> <p><em>EDITED TO ADD EXAMPLE</em></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