IT Questions and Answers :)

animated-update-image-0026

COVID-19 India HEAT MAP

A message to our readers about COVID-19

With the uncertainty surrounding the outbreak of the corona virus. We want to reassure our reader stay safe and Healthy.Be aware and alert. Work as one nation. Sanitize and disinfect all equipment before entering your home, work and anywhere.

Thursday, November 23, 2017

In PowerShell, all of the following are valid ways to create an array, except:

In PowerShell, all of the following are valid ways to create an array, except:

  • $array = %('this, 'that')
  • $array = @('this', 'that')
  • $array = ('this', 'that')
  • $array = [array]('this', 'that') 

In PowerShell, all of the following are valid ways to create an array, except:

EXPLANATION

In programming, arrays are collections of items.  In PowerShell, these items are always objects, and a single array can contain different, unrelated object types.
Typically, simply putting a comma between different items causes them to be treated together like an array.  You can also explicitly declare an array with the [array] type marker, or with the shorthand "@" symbol.
In PowerShell, the "%" symbol is an alias for "Foreach-Object", and the example above will throw an error.
Fun fact: in Perl, the "%" is used to declare a variable as a hashtable, which is similar to an array, but uses a named key index instead of an automatic number index; unlike in PowerShell, the variable prefix in Perl actually changes depending on use, so a hashtable variable would look like "%variable" instead of "$variable".
Share:

0 comments:

Post a Comment

Popular Posts