以下にサンプルコードをいくつか作成し、ラムダ式を使用してSoftwareComponents Dictionaryを照会しようとしています。問題は、クエリが型IGroupingのvarを返すことです。最初の文字列がSoftwareComponent.ComponentNameで、2番目の文字列がSoftwareComponentであるタイプのIGroupingを返すようにクエリをさらに絞り込む必要があるときです。 ComponentDescription。誰でもこれを行う方法を知っていますか? "新しいタイプの説明" "コンポーネント1" "コンポーネント2" "旧タイプ説明" "component3" "component4"ラムダ式で辞書を照会する
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 => s.ComponentName);
}
}
public class UnOwnedSoftware
{
public Dictionary<int, SoftwareComponent> SoftwareComponents
= new Dictionary<int, SoftwareComponent>();
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;
}
}
結果をどのように表示するかの例を挙げることはできますか? – LukeH
OK、私は例を追加しました。 –