![](/img/trans.png)
[英]How do I store a List/Array/ any collection of types. Or type names so they can be passed as a type to a function
[英]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.