我有一条从第二个项目开始计算所有价值(dec价值)的总和的字典。 是否可使用LINQ?
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
我有一条从第二个项目开始计算所有价值(dec价值)的总和的字典。 是否可使用LINQ?
采用LINQ可实现:
myDict.Skip(1).Sum(x => x.Value);
However, the standard Dictionary
class doesn t guarantee ordering of items, so the "first" item can be anything.
为什么不仅仅把他们归到一起,然后把第一个项目抛开?
myList.Sum(x => x.Value) - myList.First().Value;
因此,第一点是空洞的;
dict.Skip(1).Sum(ix => ix.Value);
• 便于使用准则;
var dict = new Dictionary<string, decimal>();
dict.Add("A", 1.5m); // This value will be skipped
dict.Add("B", 2.7m);
dict.Add("C", 1.3m);
dict.Add("D", 3.9m);
var total = dict.Skip(1).Sum(v => v.Value);
Console.WriteLine(total);
2. 选择第一个项目的关键,将其从中排除:
dict.Sum(T => T.Key == "FirstKey" ? 0 : T.Value);
收取<条码>电视条码> 议程项目
total = d.Skip(0).Sum(x => x.Value)
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...