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. out value?

out value?

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

    // When a program often has to try keys that turn out not to // be in the dictionary, TryGetValue can be a more efficient // way to retrieve values. string value = ""; if (openWith.TryGetValue("tif", out value)) {Console.WriteLine("For key = \"tif\", value = {0}.", value);} else {Console.WriteLine("Key = \"tif\" is not found.");} What is value? value of the dictionary i.e. in this case openWith.value?

    D 1 Reply Last reply
    0
    • H honeyman_can

      // When a program often has to try keys that turn out not to // be in the dictionary, TryGetValue can be a more efficient // way to retrieve values. string value = ""; if (openWith.TryGetValue("tif", out value)) {Console.WriteLine("For key = \"tif\", value = {0}.", value);} else {Console.WriteLine("Key = \"tif\" is not found.");} What is value? value of the dictionary i.e. in this case openWith.value?

      D Offline
      D Offline
      Dustin Metzgar
      wrote on last edited by
      #2

      This method has to return two things: a boolean indicating if the key is valid and the value associated with a key. You know that a function can only return one thing. So it uses an out parameter to return the value. So the TryGetValue method returns true if the key exists or false if the key does not exist. If the key exists, then the variable value will be set to the string associated with that key.


      Logifusion[^]

      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