Bird
0
0

Which of the following is the correct syntax to cast the string '123' to an integer in PowerShell?

easy📝 Syntax Q12 of 15
PowerShell - Variables and Data Types
Which of the following is the correct syntax to cast the string '123' to an integer in PowerShell?
A[int]'123'
Bint('123')
C(int)'123'
Dcast int '123'
Step-by-Step Solution
Solution:
  1. Step 1: Recall PowerShell casting syntax

    PowerShell uses [Type](value) to cast, e.g., [int]'123'.
  2. Step 2: Check options for correct syntax

    [int]'123' matches the correct syntax. Options A, C, and D are invalid in PowerShell.
  3. Final Answer:

    [int]'123' -> Option A
  4. Quick Check:

    Use [Type](value) for casting [OK]
Quick Trick: Use square brackets with type before value [OK]
Common Mistakes:
  • Using parentheses like a function call
  • Trying to use 'cast' keyword
  • Missing square brackets

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes