如何在 C# 中将值添加到组合框?

How do I add values to a combo box from this in c#?

我正在尝试为游戏“我的世界”创建一个启动器,并且我使用了一个库。所以基本上我试图从列表中将值添加到组合框中,但它给了我一个错误:

Argument 1: cannot convert from 'string' to 'object[]

这是我的代码:

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CmlLib.Core;
using CmlLib.Core.Auth;

namespace cosmic_cord_installer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            var path = new MinecraftPath();

            var launcher = new CMLauncher(path);

            var versions = launcher.GetAllVersions();
            foreach (var item in versions)
            {
                comboBox1.Items.AddRange(item.Name);
            }
        }

        private async void bunifuButton1_Click_1(object sender, EventArgs e)
        {
            System.Net.ServicePointManager.DefaultConnectionLimit = 256;

            var path = new MinecraftPath();

            var launcher = new CMLauncher(path);

            var versions = await launcher.GetAllVersionsAsync();
            foreach (var item in versions)
            {
                Console.WriteLine(item.Name);
            }

            var launchOption = new MLaunchOption
            {
                MaximumRamMb = 4096,
                Session = MSession.GetOfflineSession("hello"), // Login Session. ex) Session = MSession.GetOfflineSession("hello")
                VersionType = "CosmicLauncher",
                GameLauncherName = "CosmicLauncher",
                GameLauncherVersion = "2",
            };

            var process = await launcher.CreateProcessAsync("1.12.2", launchOption); // vanilla
                                                                                     // var process = await launcher.CreateProcessAsync("1.12.2-forge1.12.2-14.23.5.2838", launchOption); // forge
                                                                                     // var process = await launcher.CreateProcessAsync("1.12.2-LiteLoader1.12.2"); // liteloader
                                                                                     // var process = await launcher.CreateProcessAsync("fabric-loader-0.11.3-1.16.5") // fabric-loader

            process.Start();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void bunifuButton2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C explorer %appdata%\.minecraft";
            process.StartInfo = startInfo;
            process.Start();
        }
    }
}

这是有错误的行:

comboBox1.Items.AddRange(item.Name);

我如何以另一种方式添加值,或者我将如何修复此错误?

AddRange 方法用于添加一个值的范围。

使用Add(item.Name)