From be9b14a296750f6d892142f2eccd1e077895bccb Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Mon, 12 Apr 2021 17:24:41 +0100 Subject: [PATCH] Remove unnecessary `Array` -> `List` -> `Array` conversion in `ProcessBaseCommand.AllProcesses` (#15052) --- .../commands/management/Process.cs | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 6656dcc54..1680e17be 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -266,30 +266,17 @@ namespace Microsoft.PowerShell.Commands } /// - /// Retrieve the master list of all processes. + /// Gets an array of all processes. /// - /// + /// An array of components that represents all the process resources. /// /// MSDN does not document the list of exceptions, /// but it is reasonable to expect that SecurityException is /// among them. Errors here will terminate the cmdlet. /// - internal Process[] AllProcesses - { - get - { - if (_allProcesses == null) - { - List processes = new(); - processes.AddRange(Process.GetProcesses()); - _allProcesses = processes.ToArray(); - } + internal Process[] AllProcesses => _allProcesses ??= Process.GetProcesses(); - return _allProcesses; - } - } - - private Process[] _allProcesses = null; + private Process[] _allProcesses; /// /// Add to ,