我的中心类目前有以下代码:
public class MatchMaker : Hub
{
private List<SoloUser> soloUsers = new List<SoloUser>();
//Client Requests
public void findNewPartner(string Country, string State)
{
SoloUser soloUser = soloUsers.FirstOrDefault(s => (s.Country== Country) && (s.State == State));
if (soloUsers.Count > 0)
Clients.partnerRequestResult(soloUsers.FirstOrDefault());
else
{
soloUser = new SoloUser {
Major = Major,
School = School,
SessionId = SessionId,
Token = token
};
soloUsers.Add(soloUser);
}
}
}
问题是每当我在客户端调用此方法时,将 SoloUser 对象添加到我的soloUsers
集合中不会保存,因此当另一个用户再次调用此函数时,linq statement( soloUsers.FirstOrDefault(s => (s.School == School) && (s.Major == Major))
) 永远不会找到 SoloUser。我怎样才能做到这一点,以便我的soloUsers
集合将保存实例和添加到其中的对象?