Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs (C#)

Code before:
                    commandTable.Add(name, baseObj);
                }
                else
                {
                    var list = value as List<object>;
                    if (list != null)
                    {
                        list.Add(baseObj);
                    }
                    else
                    {
                        list = new List<object> { value, baseObj };
                        commandTable[name] = list;
                    }
                }
            }

            List<CompletionResult> endResults = null;
            foreach (var keyValuePair in commandTable)
            {
                if (keyValuePair.Value is List<object> commandList)
                {
                    var modulesWithCommand = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
                    var importedModules = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
                    var commandInfoArray = new CommandInfo[commandList.Count];
                    for (int i = 0; i < commandInfoArray.Length; i++)
                    {
                        var commandInfo = (CommandInfo)commandList[i];
                        commandInfoArray[i] = commandInfo;
                        if (commandInfo.CommandType == CommandTypes.Application)
                        {
                            continue;
                        }

                        _ = modulesWithCommand.Add(commandInfo.ModuleName);
                        if ((commandInfo.CommandType != CommandTypes.Alias && commandInfo.CommandMetadata.CommandType is not null)
                            || (commandInfo.CommandType == CommandTypes.Alias && commandInfo.Definition is not null))
                        {
                            _ = importedModules.Add(commandInfo.ModuleName);
                        }
                    }

                    int moduleCount = modulesWithCommand.Count;
                    modulesWithCommand.Clear();
                    int index;
                    if (commandInfoArray[0].CommandType == CommandTypes.Application
                        || importedModules.Count == 1
                        || moduleCount < 2)
                    {
                        // We can use the short name for this command because there's no ambiguity about which command it resolves to.
                        index = 1;

Review comment (suggestion):
I think it's better use `commandList.Count` for this loop
```suggestion
                    for (int i = 0; i < commandList.Count; i++)
```

Code after:
                {
                    commandTable.Add(name, baseObj);
                }
                else
                {
                    var list = value as List<object>;
                    if (list != null)
                    {
                        list.Add(baseObj);
                    }
                    else
                    {
                        list = new List<object> { value, baseObj };
                        commandTable[name] = list;
                    }
                }
            }

            foreach (var keyValuePair in commandTable)
            {
                if (keyValuePair.Value is List<object> commandList)
                {
                    var modulesWithCommand = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
                    var importedModules = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
                    var commandInfoList = new List<CommandInfo>(commandList.Count);
                    for (int i = 0; i < commandList.Count; i++)
                    {
                        if (commandList[i] is not CommandInfo commandInfo)
                        {
                            continue;
                        }

                        commandInfoList.Add(commandInfo);
                        if (commandInfo.CommandType == CommandTypes.Application)
                        {
                            continue;
                        }

                        modulesWithCommand.Add(commandInfo.ModuleName);
                        if ((commandInfo.CommandType == CommandTypes.Cmdlet && commandInfo.CommandMetadata.CommandType is not null)
                            || (commandInfo.CommandType is CommandTypes.Function or CommandTypes.Filter && commandInfo.Definition != string.Empty)
                            || (commandInfo.CommandType == CommandTypes.Alias && commandInfo.Definition is not null))
                        {
                            // Checks if the command or source module has been imported.
                            _ = importedModules.Add(commandInfo.ModuleName);
                        }
                    }

                    if (commandInfoList.Count == 0)
                    {
                        continue;