似乎找不到这里有什么问题,我正在使用这种方法:
public void AddPlayerToTeam(Player player, Team team)
{
Team t = new Team();
if(team.PlayersList.Count>=20)
return;
if (!(team.PlayersList.Contains(player)))
team.PlayersList.Add(player);
}
稍后在此测试中:
[TestMethod]
public void CheckTeamOfPlayer9()
{
Assert.AreEqual(wcm.GetPlayerById(9).PlayerTeam.CountryName, "Japan");
}
我收到以下错误:Object reference not set to an instance of an object.
空引用异常。这是测试运行的方法:
public Player GetPlayerById(int playerId)
{
var result = from b in Players
where b.PersonId.Equals(playerId)
select b;
return result.FirstOrDefault();
}
有人有想法吗?