gpt4 book ai didi

C#动态改变对象的属性

转载 作者:太空宇宙 更新时间:2023-11-03 18:48:32 24 4
gpt4 key购买 nike

有没有办法像这样在 C# 中更改对象的属性。

整数 = 1;

label[Number].Text = "测试";

并且结果会将 label1.Text 更改为“Test”;

希望你明白我的意思。

最佳答案

您可以将所有标签放入一个数组中:

var labels = new[] { label1, label2, label3, label4 };

然后使用数组索引器:

int number = 0;
labels[number].Text = "Test";

关于C#动态改变对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2122913/

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