c# - Group by variable integer range using Linq -


i'm trying group set of data based on range of integer, range not increase @ fixed interval.

e.g. have

item id price
1          10
2          30
3          50
4          120

i group items price 0 - 10, 11- 100, , 100-500. item 1 in group a, item 2,3, in group b, item 4 in group c.

the closest can come items group items (items.price / 10 )

then join groups different ranges.

any ideas?

thanks! jenny

parameterizing list of range ceilings...

var ceilings = new[] { 10, 100, 500 }; var groupings = items.groupby(item => ceilings.first(ceiling => ceiling >= item)); 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -