我正在制作一个图形控制类Info
它应该在屏幕上显示一些文本。文本是一些对象的字符串。我希望能够从Info
类的实例中获取该对象的最新值。如何将对象的属性绑定到另一个对象的属性? (C#)
class Info
{
public string Text;
}
void Program()
{
ClassA obj = new ClassA();
obj.name = "Instance of ClassA";
Info wind1 = new Info();
wind1.Text = obj.name; // this just copies current value, but should be a reference or something
/* obj.name value changes several times before it's time to display it again */
// Info window drawing method
foreach (var item in Windows) // Windows is List<Info>
Draw(item.Text); // this doesn't get the latest value
}
我该如何更改代码才能从绘图部分获取最新的字符串值?
我敢肯定,标题并没有尽可能多地理解它。如果你知道更好的措辞,随意编辑。 – user1306322