Hi,
I have a list like List> X where Items is a class... and another List like List Y where
StudentTasks is a class which contains two variables PersonnelNumber(int),Iseligible(bool).......
In the above list X contains personnelnumber(int) which is the key for each list member in X...
In the above list Y contains personnelnumber(int) which is one of the variable in each list member (ie StudentTasks )...
actually the personnelnumbers in X were the subset of personnelnumbers present in Y which even contains personnal numbers
other than in X....So as now
Please let me knoiw how to fetch personnelnumbers from Y(which were present in X) and the associated Iseligible values from Y...
and need to create a new Dictionary like var q=new Dictionary() where this should be populated with values from the above resultset...ie...key as personnelnumbers and iseligible as value....
populate dictionary from the intersection of two lists
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
You can do this, e.g., in the following way:
JIC: as far as I can understand, this question is not related to LinqConnect and rather concerns the common LINQ to Objects functionality. Please use this forum for the questions on LinqConnect only.
Code: Select all
IEnumerable keys = X.Select(kvp => kvp.Key);
Dictionary dictionary = Y.Where(y => keys.Contains(y.PersonnelNumber))
.Select(y => new { y.PersonnelNumber, y.IsEligible })
.ToDictionary(n => n.PersonnelNumber, n => n.IsEligible);
-
- Posts: 1
- Joined: Mon 25 Jun 2012 06:42
Re: populate dictionary from the intersection of two lists
Keep up the good work