I have 2 columns Name and Amount
我和林克一样,根据谁拥有最大数额,将姓名归还。
迄今为止,我有:
string name = (from nm in bg
select nm.Name).Max(Amount);
这显然不会奏效。
谢谢。
I have 2 columns Name and Amount
我和林克一样,根据谁拥有最大数额,将姓名归还。
迄今为止,我有:
string name = (from nm in bg
select nm.Name).Max(Amount);
这显然不会奏效。
谢谢。
string name = (from nm in bg
where nm.Amount == bg.Max(i=>i.Amount)
select nm.Name)
或
string name = (from nm in bg
orderby nm.Amount desc
select nm.Name).First()
快速办法 我可以这样认为(最后数额,然后找到最多、两条方式的物品,并且是O(n)):
decimal amount = bg.Max(x=>x.Amount);
var name = bg.First(x=>x.Amount == amount).Name; // O(n)
也可以:
// O(n^2) in worst case, O(n) in best case
bg.First(x=>x.Amount == bg.Max(x=>x.Amount)).Name;
或
bg.OrderByDescending(x=>x.Amount).First().Name; // O(n log n) in all situation
表达
bg.OrderByDescending(nm => nm.Amount).First().Name
将获得你想要的东西,但如果<条码>bg条码>是空洞的话,就会扔 throw。 如果这是一个问题,使用
var topNm = bg.OrderByDescending(nm => nm.Amount).FirstOrDefault();
www.un.org/spanish/ga/president
Using linq? and XML is there a way to convert this IEnumerable to a string array of the value parameter? List<string> idList = new List<string>(); foreach (XElement idElement in word....
I have two tables, Tags(tagid, postid, tagname) and posts(postid, name, ...) now i want to make a query that returns me all posts that have a generic amount of tags. like: i want all posts that have ...
I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...
I have a List<> of custom objects. This custom type has a property called Name which should be unique among the list. In other words, no 2 items items in the list should have the same value for ...
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. ...
When using GTK# from C# on Mono, I often find myself copying out C# data structures into Gtk.ListStore -- it would be much easier if there was a Gtk.TreeModel which wrapped an IEnumerable. Does such ...
i have list of items IList with data that looks list this: GenId TestMode 1 0 1 1 3 0 3 1 4 NULL 2 NULL i want to remove the index ...
Im looking to group and sort a Generic List<>. I have a list of objects representing files and each of these objects has a FileName, FileType and FileDate property. FileType is defined as an ...