Questions tagged [ilookup]
17 questions
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
43
votes
8 answers
Empty ILookup
I have a method that returns an ILookup. In some cases I want to return an empty ILookup as an early exit. What is the best way of constructing an empty ILookup?

Mike Q
- 22,839
- 20
- 87
- 129
30
votes
2 answers
Does .GroupBy() guarantee order in its groupings?
Say I have an (ordered) sequence of animals:
Eagle
Elephant
Tarantula
Terrapin
Tiger
and I group by first letter:
Animals.GroupBy(animal => animal.First())
will the elements of the IGroupings in the resulting sequence be in the same order as the…

spender
- 117,338
- 33
- 229
- 351
16
votes
2 answers
Is there a way to flatten a .Net ILookup into a List?
Is there a quick way to get a flattened List from an ILookup that was created from the IEnumerable extension?
Updated with example
List list = new List();
var lookup = list.ToLookup(key => key);
list =…

Joomala
- 233
- 2
- 6
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
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
Creating ILookups
I've got an ILookup generated by some complicated expression. Let's say it's a lookup of people by last name. (In our simplistic world model, last names are unique by family)
ILookup families;
Now I've got two queries I'm interested…

configurator
- 40,828
- 14
- 81
- 115
4
votes
1 answer
filter linq lookup based on values
I would like to filter a linq Lookup based on its values:
the lookup:
ILookup lookup
here's what I've got so far which isn't working:
IList cityIndexes = GetCityIndexesByNames(cities);
lookup = lookup
…

user560498
- 537
- 1
- 16
- 25
3
votes
2 answers
Linq - convert an ILookup into another ILookup
This should be simple, but I can't think of a good way to do it. How do you transform an ILookup into another ILookup? For example, how would you copy/clone an ILookup, producing another ILookup with the same keys and same groups?
Here's my lame…

Brian Berns
- 15,499
- 2
- 30
- 40
1
vote
1 answer
How can interface IGrouping yield multiple values?
I wonder what point I overlook. IGrouping is used by LINQ GroupBy. Further, the same logic is applied to ILookup, IIRC. Accordingly, they can return multiple values subject to the key specified. However, instead, I would…

Soner from The Ottoman Empire
- 18,731
- 3
- 79
- 101
1
vote
1 answer
Linq Query to get DataContext Entities based on ILookup
If I have an IEnumerable Values, I can write a Linq to Entities query, like so:
DataContext.Answers.Where(a => a.Organization == CurrentUser.Organization ||
Values.Contains(a.QuestionId))
The (Values.Contains(a.QuestionId)) part is what my…

Gunner Barnes
- 385
- 1
- 4
- 18
1
vote
1 answer
ILookup store item under multiple keys
I have a situation where I have a set of objects, these objects relate to items in a database. We create a local cache of these objects along with indexes to allow fast filtering/searching of the data. The issue I am having is converting the list of…

Neaox
- 1,933
- 3
- 18
- 29
0
votes
1 answer
How to get value from IGrouping where key and value in object match
I have a database table with three columns: CodeType, Code, Name
I am holding the values in memory, a poor man's cache if you will with the values assigned to a Lookup.
public class ShortCodeCache
{
public DateTime LastRefresh { get; set; }
…

Connie DeCinko
- 802
- 2
- 15
- 32
0
votes
0 answers
CSV file transposed to ILookup
A vendor is providing us a csv file nightly. We need to take that csv, pull out some of the columns, then import them into our in-house application. The csv, as we receive it, looks a bit like this:
StudentId, GradYear, 2014 Thing1, 2014 Thing2,…

Jazzy
- 519
- 9
- 31
0
votes
0 answers
ILookup and Casting
I got the following objects:
class Base { }
class A : Base {}
class B : Base {}
class C : Base {}
enum BaseType
{
A,
B,
C,
}
ILookup lookup = GetBaseInformation();
The GetBaseInformation method returns me a list of Base…

Hélder Gonçalves
- 3,822
- 13
- 38
- 63