Trying to use ToDictionary<>...
-
Hi All, new to LINQ, could use a pointer on fixing what I'm doing wrong please.. I have a Dictionary of int to List<MyType>, such as:
Dictionary<int, List<MyType>> myTypeDictionary
I am trying to copy this dictionary to another dictionary that will contain all elements except one
Dictionary<int, List<MyType>> myNewTypeDictionary = (from pair in myTypeDictionary where pair.Key != someValue select pair).ToDictionary<int, List<MyType>>( p=> p.Key, p=> p.Value);
According to examples of doing this, my lamda looks like other samples of using ToDictionary I've seen, & I've tried a few variations, but I'm getting a number of compile time errors. What would the correct LINQ query look like? There's other ways to accomplish what I'd like done, but now that my lambda won't work, I'm curious to see the proper code.
-
Hi All, new to LINQ, could use a pointer on fixing what I'm doing wrong please.. I have a Dictionary of int to List<MyType>, such as:
Dictionary<int, List<MyType>> myTypeDictionary
I am trying to copy this dictionary to another dictionary that will contain all elements except one
Dictionary<int, List<MyType>> myNewTypeDictionary = (from pair in myTypeDictionary where pair.Key != someValue select pair).ToDictionary<int, List<MyType>>( p=> p.Key, p=> p.Value);
According to examples of doing this, my lamda looks like other samples of using ToDictionary I've seen, & I've tried a few variations, but I'm getting a number of compile time errors. What would the correct LINQ query look like? There's other ways to accomplish what I'd like done, but now that my lambda won't work, I'm curious to see the proper code.
Insteand of
.ToDictionary<int,>>(p=> p.Key, p=> p.Value)
Write.ToDictionary(p=> p.Key, p=> p.Value)
I think it will workAbhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
Create .NET Templates -
Insteand of
.ToDictionary<int,>>(p=> p.Key, p=> p.Value)
Write.ToDictionary(p=> p.Key, p=> p.Value)
I think it will workAbhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
Create .NET Templates -
Oh yes ... sorry for the spelling mistakes I made... . ;P ;P
Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
Create .NET Templates