我需要通過枚舉值得到一個總和。看到這個例子:C#LINQ的總和
在這種來源:
namespace ConsoleApplication
{
enum fruits { Orange, Grape, Papaya }
class item
{
public fruits fruit;
public string foo;
}
class Program
{
static void Main(string[] args)
{
item[] list = new item[]
{
new item() { fruit = fruits.Orange, foo = "afc" },
new item() { fruit = fruits.Orange, foo = "dsf" },
new item() { fruit = fruits.Orange, foo = "gsi" },
new item() { fruit = fruits.Orange, foo = "jskl" },
new item() { fruit = fruits.Grape, foo = "mno" },
new item() { fruit = fruits.Grape, foo = "pqu" },
new item() { fruit = fruits.Grape, foo = "tvs" },
};
var vTotals = from... //Here
}
}
}
我想vTotals是類型
Dictionary<fruits, int>
的 與價值觀
{
{ fruits.Orange, 4 }
{ fruits.Grape, 3 }
{ fruits.Papaya, 0 }
}
我該怎麼辦呢與Linq?
在此先感謝
完美!!!這正是我需要的! – Riera