【发布时间】:2020-07-22 11:40:06
【问题描述】:
我有两节课。 这是第一个:
namespace Working_Times.Klassen
{
class calcHours
{
//Right here i need the value of startTime from MainPage
}
}
第二个叫做MainPage
我已经尝试过 calcHours
MainPage mP = new MainPage();
mP.startTime = 3; //for example, if startTime was an integer
//it says: mP.startTime not available in the current context
startTime not available in the current context
非常感谢 :) 很多人一直在回答我,问题是访问权限。 就我而言,我想,这不是问题。我已经尝试将每个变量都更改为公共变量。还是不跑。 顺丰
【问题讨论】:
-
Nobody ever read exception messages :( "mP.startTime not available in the current context " 表示
mP对象中名为startTime的字段在调用方法的上下文。 -
MainPage类中必须有一个字段/变量/属性,名称为startTime,它应该是public。像这样public int startTime; -
确保该属性是公开的。
-
问题Public Fields versus Automatic Properties 可能有您正在寻找的答案
标签: c# visual-studio xaml uwp