Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:36:22+00:00 2026-05-31T07:36:22+00:00

The only method I have found is a direct cast: > $numberAsString = 10

  • 0

The only method I have found is a direct cast:

> $numberAsString = "10"
> [int]$numberAsString
10

Is this the standard approach in Powershell? Is it expected that a test will be done before to ensure that the conversion will succeed and if so how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:36:23+00:00Added an answer on May 31, 2026 at 7:36 am

    Using .net

    [int]$b = $null #used after as refence
    $b
    0
    [int32]::TryParse($a , [ref]$b ) # test if is possible to cast and put parsed value in reference variable
    True
    $b
    10
    $b.gettype()
    
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     Int32                                    System.ValueType
    

    note this (powershell coercing feature)

    $a = "10"
    $a + 1 #second value is evaluated as [string]
    101 
    
    11 + $a # second value is evaluated as [int]
    21
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The only reliable method that I a have found for using a script to
I have found that the only sure way to test modifications I do to
I have method in a class that I need to make sure is only
I have these two methods on a class that differ only in one method
What would I do if I want to have a generic method that only
I have only simple data types in method signature of service (such as int,
I am having some trouble with UITableView's reloadData method. I have found that it
Is there a method like isiterable ? The only solution I have found so
I have found an extension method that handles sorting and paging for LINQ .
I'm trying to test my site under heavy load. I have found that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.