gpt4 book ai didi

c# - 如何使用公共(public)字符串填充文本框?

转载 作者:太空宇宙 更新时间:2023-11-03 21:39:59 25 4
gpt4 key购买 nike

我有一个似乎无法解决的令人沮丧的问题。

我尝试用来自公共(public)静态字符串的文本填充 TextBox。但是当我运行该程序时,它只显示一个空白文本框,其中什么也没有。

我没有任何错误,所以我很难理解我做错了什么。

这是我的代码:

public ShowMp3()
{
InitializeComponent();
OverzichttxtBox.Text = OverzichtMP3();
}

public static String OverzichtMP3()
{
String overzicht = "";

foreach (Mp3Player player in Mp3.GetPlayers())
overzicht = overzicht + "ID: " + Convert.ToString(player.id) + "\r\n" +
"Merk: " + player.make + "\r\n" + "Model: " + player.model +
"\r\n" + "MB-size: " + player.mBSize + "\r\n" + "Prijs: " +
player.price + "\r\n" + "\r\n";

return overzicht;
}

Mp3.GetPlayers() 是这样的:

private static ArrayList players = new ArrayList();

public static void Initialize()
{
Mp3Player player1 = new Mp3Player(1, "GET Technologies .inc", "HF 410", 4096, 129.95M, 500);
Mp3Player player2 = new Mp3Player(2, "Far & Loud", "XM 600", 8192, 224.95M, 500);
Mp3Player player3 = new Mp3Player(3, "Innotivative ", "Z3", 512, 79.95M, 500);
Mp3Player player4 = new Mp3Player(4, "Resistance S.A.", "3001", 4096, 124.95M, 500);
Mp3Player player5 = new Mp3Player(5, "CBA", "NXT Volume", 2048, 159.05M, 500);

players.Add(player1);
players.Add(player2);
players.Add(player3);
players.Add(player4);
players.Add(player5);
}

public static ArrayList GetPlayers()
{
return players;
}

最佳答案

我怀疑问题是你从来没有调用 Mp3.Initialize() .您可以将其添加到 Mp3 中的静态构造函数中类:

private static List<Mp3Player> players = new List<Mp3Player>();

static Mp3()
{
Initialize();
}

// This can be private now...
private static void Initialize()
{
....

请注意,您可能想要更改 ArrayListList<Mp3Player> ,还有。

关于c# - 如何使用公共(public)字符串填充文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19845047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com