Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Trying to use ToDictionary<>...

Trying to use ToDictionary<>...

Scheduled Pinned Locked Moved LINQ
linqcsharpdatabasefunctionalquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wes Jones
    wrote on last edited by
    #1

    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 oneDictionary<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.

    A 1 Reply Last reply
    0
    • W Wes Jones

      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 oneDictionary<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.

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Insteand of .ToDictionary<int,>>(p=> p.Key, p=> p.Value) Write .ToDictionary(p=> p.Key, p=> p.Value) I think it will work

      Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
      Create .NET Templates

      W 1 Reply Last reply
      0
      • A Abhishek Sur

        Insteand of .ToDictionary<int,>>(p=> p.Key, p=> p.Value) Write .ToDictionary(p=> p.Key, p=> p.Value) I think it will work

        Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
        Create .NET Templates

        W Offline
        W Offline
        Wes Jones
        wrote on last edited by
        #3

        Thanks, that does the trick! I'll make a note of the difference for future reference.

        A 1 Reply Last reply
        0
        • W Wes Jones

          Thanks, that does the trick! I'll make a note of the difference for future reference.

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups