C# 现在显示标签文本

C# 现在显示标签文本,c#,textbox,label,C#,Textbox,Label,我在windows窗体上有一个标签没有显示其文本。标签从另一个名为StudentSearch的类中的文本框中获取文本。看起来是这样的: labelStuName.Text = StudentSearch.firstname; 当我运行应用程序时,它现在会显示任何文本 根据我在上面的评论中看到的,在类中添加firstname属性,如下所示public firstname{get;set}或将firstname字段公开 然后,如果使用该属性,则代码将变为labelStuName.Text=Stu

我在windows窗体上有一个标签没有显示其文本。标签从另一个名为StudentSearch的类中的文本框中获取文本。看起来是这样的:

labelStuName.Text = StudentSearch.firstname; 

当我运行应用程序时,它现在会显示任何文本

根据我在上面的评论中看到的,在类中添加firstname属性,如下所示
public firstname{get;set}
或将firstname字段公开


然后,如果使用该属性,则代码将变为
labelStuName.Text=StudentSearch.Firstname.Text
,或者如果将Firstname作为公共变量,则代码将保持为
labelStuName.Text=StudentSearch.Firstname.Text

,需要更好的代码示例来说明您正在尝试执行的操作。那作业是在你按下按钮还是什么之后发生的?
StudentSearch
是另一门课吗?
firstname
是一个变量,您已将另一个文本框的值赋给该变量?@CNuts Yes。让我换个更好的example@secretlygayfrog当您尝试将
firstname
分配给
labelStuName
时,是否确定它有一个值。因此表单上有一个标签,该标签的文本为label1,标签名称为labelStuName。我有代码labelStuName.Text=StudenSearch.firstname;其中firstname是类StudentSearch中的文本框