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. C#
  4. accessing dictionary within another one?

accessing dictionary within another one?

Scheduled Pinned Locked Moved C#
questiontutorial
3 Posts 3 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.
  • H Offline
    H Offline
    honeyman_can
    wrote on last edited by
    #1

    Hi guys! This is my method signature:public static string Translate(string translationCode, string culture, Dictionary> input) i would like to know how to access the value of the 'input' dictionary within the method? e.g. if(input.ContainsKey(culture)) { if(how do I check they 'key' of the inner dictionary?) { //use the value of the inner dictionary then how would i access the value of the inner dictionary } } I hope this makes sense. Thanks

    R C 2 Replies Last reply
    0
    • H honeyman_can

      Hi guys! This is my method signature:public static string Translate(string translationCode, string culture, Dictionary> input) i would like to know how to access the value of the 'input' dictionary within the method? e.g. if(input.ContainsKey(culture)) { if(how do I check they 'key' of the inner dictionary?) { //use the value of the inner dictionary then how would i access the value of the inner dictionary } } I hope this makes sense. Thanks

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      I think this should work:

      if (input.ContainsKey (culture)) {
      Dictionary d = input [culture];
      if (d.Contains (translationCode))
      return d [translationCode];
      return String.Empty;
      }

      /ravi

      My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • H honeyman_can

        Hi guys! This is my method signature:public static string Translate(string translationCode, string culture, Dictionary> input) i would like to know how to access the value of the 'input' dictionary within the method? e.g. if(input.ContainsKey(culture)) { if(how do I check they 'key' of the inner dictionary?) { //use the value of the inner dictionary then how would i access the value of the inner dictionary } } I hope this makes sense. Thanks

        C Offline
        C Offline
        Christian Wulff
        wrote on last edited by
        #3

        Just apply every operation to the inner dictionary to input[culture]:

        if(input.ContainsKey(culture))
        {
        if(input[culture].ContainsKey(innerDictionaryKey))
        {
        string theValueYouWant = input[culture][innerDictionaryKey];
        }
        }

        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