IT Questions and Answers :)

Wednesday, July 10, 2019

In PowerShell, all variable names begin with which character?

In PowerShell, all variable names begin with which character?

  • *
  • %
  • #

In PowerShell, all variable names begin with which character?

EXPLANATION

In PowerShell, variable names start with the $ character. You can assign a value to a variable using the assignment operator, which is the = character. You can create a variable by simply assigning it a value. For example, the command
$myName = "Ferb"
creates a variable named $myName and assigns it a string value. The double quotes (" ") indicate that a string value is being assigned to the variable.
As I mentioned previously, PowerShell variables are really objects. In simple terms, objects can contain data (properties) and operations you can perform on the data (methods). In this example, the $myName variable is really a String object. As with other objects, the String object has both properties and methods. For example, the Length property of a String object tells you the number of characters in the string, and the ToUpper method gives you a copy of the string converted to uppercase. You can access both properties and methods using a dot (.) after the variable name. Properties don't use parentheses ( ), but methods do. For example, the command
$myName.Length
returns a value of 4 because the variable's value (Ferb) is four characters long. The command
$myName.ToUpper()
returns FERB.

 

Share:

0 comments:

Post a Comment

Popular Posts