我有一个用于在游戏中保存交互的类,当一个人从游戏状态中获取值以创建这个类的新实例,然后发送它,这很好,问题是当我试图在级别的末尾获得值时,该类的每个实例对于该属性都具有相同的值,与该类的最后一个声明对象相同。
public class reactionOrOmission
{
public bool reacted
{
get { return _reacted; }
set { _reacted = value; }
}
public float reactionTime
{
get { return _reactionTime; }
set { _reactionTime = value; }
}
public bool correct
{
get { return _correct; }
set { _correct = value; }
}
public int[] flagType
{
get { return _flagType; }
set { _flagType = value; }
}
public float generalTime
{
get { return _generalTime; }
set { _generalTime = value; }
}
public string focus
{
get
{
return _focus != null ? _focus : "non_focusable";
}
set { _focus = value; }
}
private bool _reacted;
private float _reactionTime;
private bool _correct;
private int[] _flagType;
private float _generalTime;
private string _focus;
public reactionOrOmission(bool Reacted, float ReactionTime, bool Correct, int[] FlagType, float GeneralTime)
{
reacted = Reacted;
reactionTime = ReactionTime;
correct = Correct;
flagType = FlagType;
generalTime = GeneralTime;
if (Tobii.Gaming.TobiiAPI.GetFocusedObject() == null)
{
focus = "non_focusable";
}
else
{
///nonimportant///
}
}
}我认为这可能与整数数组有关,但我尝试了arrayList和list,同样的情况也发生了。
发布于 2022-10-27 18:47:43
我认为您的类是正确的,但是在创建实例之后,您使用了不正确的实例或可能不正确的用法……我运行了您的类并设置了4个不同的实例,每个实例都有不同的值。所以你的课堂用法是不正确的!
https://stackoverflow.com/questions/74223956
复制相似问题