I am looping through a hash ans want to add total score to the value of the hash key but it keeps saying object not set to instance of object on the player.TotalPoints = bp.TotalScore; line below is my c# code
public void PointsDecider()
{
foreach(DictionaryEntry HomeHshKey in HomeHsh)
{
//Get the players data
Player p = HomeHshKey.Value as Player;
//We need position so we can work out points
int position = p.PositionID;
int numberRuns = p.NumberRuns;
decimal strikeRate = p.StrikeRate;
int esaPlayerID = p.EsaPlayerID;
int wickets = p.Wickets;
int teamid = p.TeamID;
decimal economy = p.Economy;
if (position == 45)
{
//Edit players key in hash
player = (Player)HomeHsh[HomeHshKey];
bp = new BowlerPoints(numberRuns,strikeRate, BonusHsh,esaPlayerID, wickets, WinnerID, teamid, economy);
player.TotalPoints = bp.TotalScore;
}
}
}
luke_bryant
Member
396 Points
361 Posts
Object not set to instance of object
Apr 30, 2012 01:16 PM|LINK
Hi programmers,
I am looping through a hash ans want to add total score to the value of the hash key but it keeps saying object not set to instance of object on the player.TotalPoints = bp.TotalScore; line below is my c# code
public void PointsDecider() { foreach(DictionaryEntry HomeHshKey in HomeHsh) { //Get the players data Player p = HomeHshKey.Value as Player; //We need position so we can work out points int position = p.PositionID; int numberRuns = p.NumberRuns; decimal strikeRate = p.StrikeRate; int esaPlayerID = p.EsaPlayerID; int wickets = p.Wickets; int teamid = p.TeamID; decimal economy = p.Economy; if (position == 45) { //Edit players key in hash player = (Player)HomeHsh[HomeHshKey]; bp = new BowlerPoints(numberRuns,strikeRate, BonusHsh,esaPlayerID, wickets, WinnerID, teamid, economy); player.TotalPoints = bp.TotalScore; } } }