Questions tagged [igrouping]

The .NET interface for a collection of objects with a common key

The IGrouping interface, introduced in as part of , represents "a collection of objects with a common key".

It is typically encountered as a result of a GroupBy operation - for example

IGrouping<System.Reflection.MemberTypes, System.Reflection.MemberInfo> group =
    typeof(String).GetMembers().
    GroupBy(member => member.MemberType).
    First();

The members of the interface are used when handling results of any GroupBy operation. Questions that deal with handling the results of such GroupBy operations, or which otherwise construct objects that implement this interface, are expected to have this tag.

The interface itself defines available methods and properties which generally involve working with the objects inside the collection (or group).

76 questions
291
votes
8 answers

How to get values from IGrouping

I have a question about IGrouping and the Select() method. Let's say I've got an IEnumerable> in this way: var groups = list.GroupBy(x => x.ID); where list is a List. And now I need to pass values of each IGrouping to…
Illia Ratkevych
  • 3,507
  • 4
  • 29
  • 35
188
votes
4 answers

Get "Value" property in IGrouping

I have a data structure like public DespatchGroup(DateTime despatchDate, List products); And I am trying to do... var list = new List(); foreach (var group in dc.GetDespatchedProducts().GroupBy(i => i.DespatchDate)) { …
fearofawhackplanet
  • 52,166
  • 53
  • 160
  • 253
83
votes
3 answers

ILookup vs. IGrouping

I've been having trouble articulating the differences between ILookup and IGrouping, and am curious if I understand it correctly now. LINQ compounded the issue by producing sequences of IGrouping items while also giving me a…
mckamey
  • 17,359
  • 16
  • 83
  • 116
14
votes
3 answers

IEnumerable to IEnumerable

So I have this: IEnumerable> groupedObjects = myObjectsResults.GroupBy(x => x.Id); The question is, how do I turn this result into an IEnumerable>? This is as far as I could take…
Doug Peters
  • 529
  • 2
  • 8
  • 17
9
votes
1 answer

LINQ Convert from IGrouping to Lookup

I have two variables of type ILookup. I wanted to use Union or Concat to combine their values and assign the result to a third variable of the same type. Both Union and Concat return IGrouping. It must be dead simple to convert IGrouping to the…
Anna
8
votes
1 answer

IQueryable IGrouping how to work

i return such type IQueryable< IGrouping> List() how can i work with it? like with generic List ?
kusanagi
  • 14,296
  • 20
  • 86
  • 111
7
votes
1 answer

Mapping a grouped collection using AutoMapper

I have the following code which is not working: var groupedZones = this._zoneDataManager.GetZonesGroupedByCountry(); IEnumerable> zonesToReturn = Mapper.Map>,…
TaniaMaria
  • 83
  • 1
  • 3
6
votes
3 answers

LINQ: Grouping SubGroup

How to group SubGroup to create list of Continents where each Continent has it own counties and each country has its own cities like this table Here is the t-sql: select Continent.ContinentName, Country.CountryName, City.CityName from …
Lucy
  • 243
  • 1
  • 4
  • 18
5
votes
3 answers

Linq: Create empty IGrouping

I would like to create a function using Linq that summarizes an incoming sequence of values. The function should look something like this: IDictionary> Summarize(IEnumerable values) { return values …
Brian Berns
  • 15,499
  • 2
  • 30
  • 40
5
votes
3 answers

Linq Lambda GroupBy and OrderBy

I would like to Group by and then order the items within the group. how do i do it with lamda, using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { …
Ravi
  • 51
  • 1
  • 1
  • 2
5
votes
3 answers

How can I return the Value from a .NET IGrouping via a Key?

I'm struggling to figure out how to retrieve the Value part of an IGrouping instance. I have the following: IList results = someList.GroupBy(x => x.UserName); And I now wish to iterate through each collection and…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
5
votes
1 answer

How to order IGrouping without changing its type?

I have an oject of the type IGrouping and would like to order the elements inside the group without changing the type of the object. In other words, I have var tmp = group.OrderBy(x => x); with group being of type IGrouping
Tim Pohlmann
  • 4,140
  • 3
  • 32
  • 61
5
votes
4 answers

Difference between the returned values of two selector functions in this code

var Students = new Dictionary(); Students.Add( "Bob" , 60); Students.Add( "Jim" , 62); Students.Add( "Jack", 75); Students.Add( "John", 81); Students.Add( "Matt", 60); Students.Add( "Jill", 72); Students.Add( "Eric", 83); Students.Add(…
5
votes
3 answers

How to get values out of IGrouping?

I have applied IGrouping<> over a list - here's what it looks like: IEnumerable> Tiers { get { return ActiveNodes.GroupBy(x => new TierRequest(x.TierID, x.TierTimeout, x.TierMaxRequests)); } } Later in my…
dotnetnoob
  • 10,783
  • 20
  • 57
  • 103
5
votes
1 answer

Create IGrouping from an already grouped datastructure

I've got a LINQ problem thats got me a little stumped. I can see plenty of alternative ways to find a solution but would like to try to solve the problem cos its bugging me! public enum AnimalType { Cat, Dog, Rodent } var…
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
1
2 3 4 5 6