Bird
0
0

Which of the following is the correct syntax to add a key-value pair 'Name' = 'Alice' to an existing hash table $person?

easy📝 Syntax Q12 of 15
PowerShell - Variables and Data Types
Which of the following is the correct syntax to add a key-value pair 'Name' = 'Alice' to an existing hash table $person?
A$person[Name] = 'Alice'
B$person.Name = Alice
C$person->Add('Name', 'Alice')
D$person.Add('Name', 'Alice')
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to add key-value pairs to hash tables

    PowerShell hash tables have an Add() method to add new keys and values.
  2. Step 2: Identify correct method call syntax

    The correct syntax is $person.Add('Name', 'Alice'). Note that the Add() method specifically adds new entries.
  3. Final Answer:

    $person.Add('Name', 'Alice') -> Option D
  4. Quick Check:

    Add key-value with Add() method [OK]
Quick Trick: Use Add() method to add new keys to hash tables [OK]
Common Mistakes:
  • Using -> which is not PowerShell syntax
  • Using dot notation with unquoted value
  • Using unquoted key in square brackets

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes