Bird
0
0

How do you access the value for key 'City' in a hash table named $info?

easy📝 Conceptual Q2 of 15
PowerShell - Variables and Data Types
How do you access the value for key 'City' in a hash table named $info?
A$info['City']
B$info.City
C$info->City
D$info(City)
Step-by-Step Solution
Solution:
  1. Step 1: Recall the syntax for accessing hash table values

    In PowerShell, hash table values are accessed using square brackets and quotes around the key.
  2. Step 2: Evaluate each option

    $info['City'] uses $info['City'], which is the correct syntax. $info.City is incorrect because dot notation does not work for hash tables. Options C and D are invalid syntax.
  3. Final Answer:

    $info['City'] -> Option A
  4. Quick Check:

    Access hash table value = $hash['key'] [OK]
Quick Trick: Use square brackets and quotes to access hash table keys [OK]
Common Mistakes:
  • Using dot notation for hash tables
  • Using parentheses instead of brackets
  • Omitting quotes around keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes