3

I'm trying to understand why this array count is not resulting in 0

@($null).Count

Output:

1
3
  • 6
    Because that's an array with one item in it ($null). It's not empty. @().Count returns zero. Commented Jul 6, 2017 at 14:05
  • @Bill_Stewart Nice. Please consider putting in an answer so we can get it out of the unanswered queue, and upvote etc. Commented Jul 6, 2017 at 14:20
  • Done, with a bit of elaboration. Commented Jul 6, 2017 at 14:24

1 Answer 1

9

@($null) is an array with a single $null element (hence the Count property is 1). Likewise @($null,$null).Count is 2, and @().Count is 0. Keep in mind that @($null) emits $null to the pipeline, so the Count property returned from @($null) | Measure-Object will be 0.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.