English 中文(简体)
利用Mlambda填写名单
原标题:Filtering a List using lambda

我的物体有:财产识别、品牌识别、品牌标识、国歌和型号。

i 需显示五大大品牌,品牌可能有多种识别器,因此我需要按品牌分类。

 listing.OrderByDescending(o => o.numPage).GroupBy(o=> o.brandName).Take(5).ToList();

单是看什么,但这不是有效的法典。

最佳回答

象某个品牌一样,它有好几张身份识别器,你希望五大大品牌按num子分类。 是否正确

如果是这样的话,可尝试如下:

var query = listing
  .GroupBy(x => x.brandName)
  .OrderByDescending(brands => brands.Sum(x => x.numPage))
  .Select(x => x.Key)
  .Take(5);

注:在<代码> 类别By操作之后,你现在转过一组品牌而不是单项。 因此,请<代码>num 页: 1 我们需要为该集团的所有品牌目标进行总结。 <代码>.Select(x =>x.Key)将选定该组所依据的原始<代码>brandName。

问题回答

公正审理并发挥作用:

public class Listing
{
    public int ID { get; set; }
    public int BrandID { get; set; }
    public string BrandName { get; set; }
    public int NumPages { get; set; }
    public Type Type { get; set; }    
}

此处过滤

Listing listing1 = new Listing() { NumPages = 2, BrandName = "xx" };
Listing listing2 = new Listing() { NumPages = 2, BrandName = "xx" };
Listing listing3 = new Listing() { NumPages = 2, BrandName = "xx" };
Listing listing4 = new Listing() { NumPages = 3, BrandName = "xxxxx" };

List<Listing> allListings = new List<Listing>() { listing1, listing2, listing3, listing4 };

var result = allListings.OrderByDescending(x => x.NumPages).GroupBy(x => x.BrandName).Take(5);




相关问题
Anyone feel like passing it forward?

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. ...

NSArray s, Primitive types and Boxing Oh My!

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 ...

C# Marshal / Pinvoke CBitmap?

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 ...

How to Use Ghostscript DLL to convert PDF to PDF/A

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, ...

Linqy no matchy

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. ...

热门标签