簡體   English   中英

我如何做到這一點,而不是名稱已經在數組中,用戶必須將名稱輸入到數組中?

[英]how do i make it so that instead of names already being in the array that the user has to input names into the array?

using System;
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;

namespace namegenerator1._2
{
    public partial class Form1 : Form
    { 
        string[] FirstNames = { "jan", "jaap", "sjuul", "koen" };
        
        Random rand = new Random();

        public Form1()
        {
            InitializeComponent();
        }

        private void btn_generate_Click(object sender, EventArgs e)
        {
            int indexFirstName = rand.Next(FirstNames.Length);

            this.txtbox_FirstName.Text = FirstNames[indexFirstName];
        }
    }
}

這基本上是一個從數組生成隨機名稱的小盒子。 我需要做到這一點,以便在用戶開始之前,他需要自己輸入一堆名字。 我不知道該怎么做。

您可以檢查數組長度以查看是否有足夠的游戲,或者按照建議使用列表。

如果 array.Length 不夠,請使用輸入框或文本框請求用戶輸入。

輸入將 go 在數組/列表中使用 list.Add 或通過重新排列數組

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM