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;
}
}
}
hi, already i have expained to read value from Dictionary using DictionaryEntry, but again you made mistake...
inside if condn you need to change code like this : player =(Player)HomeHsh[HomeHshKey.Key];
publicvoidPointsDecider() {foreach(DictionaryEntryHomeHshKeyinHomeHsh) { //Get the players data Player p =HomeHshKey.ValueasPlayer; //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.Key];
bp =newBowlerPoints(numberRuns,strikeRate,BonusHsh,esaPlayerID, wickets,WinnerID, teamid, economy);
player.TotalPoints= bp.TotalScore; } } }
Thanks,
Karthick S
Marked as answer by luke_bryant on Apr 30, 2012 01:37 PM
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; } } }karthicks
All-Star
31382 Points
5424 Posts
Re: Object not set to instance of object
Apr 30, 2012 01:21 PM|LINK
hi, already i have expained to read value from Dictionary using DictionaryEntry, but again you made mistake...
inside if condn you need to change code like this : player = (Player)HomeHsh[HomeHshKey.Key];
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.Key];
bp = new BowlerPoints(numberRuns,strikeRate, BonusHsh,esaPlayerID, wickets, WinnerID, teamid, economy);
player.TotalPoints = bp.TotalScore;
}
}
}
Karthick S
luke_bryant
Member
396 Points
361 Posts
Re: Object not set to instance of object
Apr 30, 2012 01:35 PM|LINK
Hi,
sorry for that I saw your email as well, just a habit I have, but once again thanks for your help :)