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 8818057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:00:19+00:00 2026-06-14T05:00:19+00:00

My source code: # $arr = @(); results in same behaviour $arr = New-Object

  • 0

My source code:

# $arr = @(); results in same behaviour
$arr = New-Object System.Collections.ArrayList;

$arr.Count;
$arr += "z";

$arr.Count;
$arr.Clear();
$arr.Count;

Output:

0
1
1

  • 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-06-14T05:00:20+00:00Added an answer on June 14, 2026 at 5:00 am

    Powershell does some array-casting trickery when you do +=, so the easy solution is to do $arr.Add("z"). Then $arr.Clear() will act like you expect.

    To clarify:

    1. @() is a Powershell array. It uses +=, but you can’t Clear it. (You can, however, do $arr = @() again to reset it to an empty array.)
    2. ArrayList is the .NET collection. It uses .Add, and you can Clear it, but for some reason if you += it, Powershell does some weird array coercion. (If any experts care to comment on this, awesome.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Source code is present at run time in production system (though it may be
The source code editor in XCode 3.1 has a new feature where your compiler
Source Code of LoginAction.java package com.test; import java.util.ArrayList; import java.util.List; public class LoginAction {
source code ... Thing is, if i specify required metadata using fluent modelmetadata provider
[Source Code] data FooBar = Foo | Bar [Command] $ ghc -c foo_bar.hs foo_bar.hs:1:0:
Superclass source code public class Date { private int month; private int day; private
The source code looks very similar: pump , pipe . Why would I use
commit source code into git repository with emacs vc-mode. I used Chinese characters to
I've a source code(test.cpp) that supposed to display three images(color, grayscale and canny) copied
when checking the source code of a site on firefox I got this on

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.