Why do I get this object type in an array?

Welcome Forums General PowerShell Q&A Why do I get this object type in an array?

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
9 months, 1 week ago.

  • Author
    Posts
  • #92815

    Participant
    Points: 7
    Rank: Member

    Can someone please help me understand this

    @("taco").gettype()
    This outputs the type that I would expect

    (&{@("taco")}).gettype()
    In a scriptblock it outputs a string. Same thing for a function obviously.

    Any help will be appreciated.

  • #92821

    Keymaster
    Points: 1,619
    Helping HandTeam Member
    Rank: Community Hero

    In the latter case you're forcing the shell to evaluate the array and enumerate its contents. Given that it has one item, which is a string, that's what you get. That's standard .NET behavior, not really PowerShell per se.

    • #92833

      Participant
      Points: 7
      Rank: Member

      Thanks Don. That makes sense.

The topic ‘Why do I get this object type in an array?’ is closed to new replies.