Note that there are some explanatory texts on larger screens.

plurals
  1. POQuerying a Dictionary with a Lambda Expression
    primarykey
    data
    text
    <p>I've created some sample code below, and am trying to use a lambda expression to query against the SoftwareComponents Dictionary. The problem is that the query returns a var of type IGrouping, when what I need to do is further refine the query so that it returns a type of IGrouping where the first string is the SoftwareComponent.ComponentName, and the second string is the SoftwareComponent.ComponentDescription. Anyone know how to do this?</p> <p>I was hoping the data returned would look something like: "New Type Description" "component1" "component2" "Old Type Description" "component3" "component4"</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { UnOwnedSoftware software = new UnOwnedSoftware(); var components = software.SoftwareComponents.Values. GroupBy(s =&gt; s.ComponentName); } } public class UnOwnedSoftware { public Dictionary&lt;int, SoftwareComponent&gt; SoftwareComponents = new Dictionary&lt;int, SoftwareComponent&gt;(); public UnOwnedSoftware() { SoftwareComponent component1 = new SoftwareComponent ("component1", 1, "New Type Description"); SoftwareComponent component2 = new SoftwareComponent ("component2", 2, "New Type Description"); SoftwareComponent component3 = new SoftwareComponent ("component3", 3, "Old Type Description"); SoftwareComponent component4 = new SoftwareComponent ("component4", 4, "Old Type Description"); SoftwareComponents.Add(1, component1); SoftwareComponents.Add(2, component2); SoftwareComponents.Add(3, component3); SoftwareComponents.Add(4, component4); } } public class SoftwareComponent { public string ComponentName { get; set; } public int ID { get; set; } public string ComponentDescription { get; set; } public SoftwareComponent(string componentName, int id, string componentDescription) { ComponentName = componentName; ID = id; ComponentDescription = componentDescription; } } </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.
 

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