Questions tagged [ilookup]
16 questions
76
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…
![](../../users/profiles/43217.webp)
mckamey
- 16,875
- 15
- 76
- 114
33
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?
![](../../users/profiles/184581.webp)
Mike Q
- 21,350
- 19
- 80
- 124
22
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…
![](../../users/profiles/14357.webp)
spender
- 106,080
- 28
- 202
- 324
14
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 =…
![](../../users/profiles/261143.webp)
Joomala
- 213
- 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
4
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
…
![](../../users/profiles/344223.webp)
brianberns
- 6,160
- 2
- 29
- 35
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
…
![](../../users/profiles/560498.webp)
user560498
- 537
- 1
- 15
- 25
4
votes
2 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…
![](../../users/profiles/9536.webp)
configurator
- 38,246
- 13
- 76
- 112
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…
![](../../users/profiles/4990642.webp)
snr
- 13,515
- 2
- 48
- 77
1
vote
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…
![](../../users/profiles/344223.webp)
brianberns
- 6,160
- 2
- 29
- 35
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…
![](../../users/profiles/548776.webp)
Gunner Barnes
- 385
- 1
- 6
- 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…
![](../../users/profiles/671552.webp)
Neaox
- 1,764
- 3
- 16
- 29
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,…
![](../../users/profiles/973828.webp)
Jazzy
- 499
- 7
- 29
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…
![](../../users/profiles/1468927.webp)
Hélder Gonçalves
- 3,092
- 12
- 33
- 63
0
votes
5 answers
What's the best way to split a list of strings to match first and last letters?
I have a long list of words in C#, and I want to find all the words within that list that have the same first and last letters and that have a length of between, say, 5 and 7 characters. For example, the list might have:
"wasted was washed washing…
![](../../users/profiles/3473853.webp)
user3473853
- 3
- 4