Link to home
Create AccountLog in
Avatar of DColin
DColinFlag for Thailand

asked on

Unknown error message

Hi Experts,

What does the error message (below) mean? It is generated by the attached code snippet.

Error      1      An object reference is required for the non-static field, method, or property 'ConsoleApplication1.Program.DoRating(double, double, int, double, double, int, double)'

 
static void Main(string[] args)
        {
            var RatingResult = new RatingQuad();

            RatingResult = DoRating(30.123, 1.123, 1, 25.123, 1.123, 0, 28.7);

        }

Open in new window

Avatar of sfaisalawan
sfaisalawan
Flag of United Kingdom of Great Britain and Northern Ireland image

Dear The Object you are going to create Rating Result is wrong. do this

RatingResult rs=new RatingQuad();
rs.DoRating(.....................);

First you are assigning RatingResult =new RatingQuad();
and then RatingResult=DoRating(.............);
which is wrong.
you are creating new object not a new variable.
Avatar of DColin

ASKER

Hi sfaisalawan:

I have changed the code as you suggest (see attached) and I get the following error message.

Error      1      The type or namespace name 'RatingResult' could not be found (are you missing a using directive or an assembly reference?)

 
static void Main(string[] args)
        {
            RatingResult rs = new RatingQuad();

            rs.DoRating(30.123, 1.123, 1, 25.123, 1.123, 0, 28.7);

        }

Open in new window

SOLUTION
Avatar of sfaisalawan
sfaisalawan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of DColin

ASKER

Hi

Yes I have created the RatingQuad class. Here is all the code.
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Moserware.Skills.Numerics;
using Moserware.Skills.TrueSkill;
using Moserware.Skills;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var RatingResult = new RatingQuad();

            RatingResult = DoRating(30.123, 1.123, 1, 25.123, 1.123, 0, 28.7);

        }

        private RatingQuad DoRating(double homeMu, double homeSigma, int homeScore, double awayMu, double awaySigma, int awayScore, double drawPercentage)
        {/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            TwoPlayerTrueSkillCalculator calc = new TwoPlayerTrueSkillCalculator();

            var player1 = new Player(1);
            var player2 = new Player(2);
            var gameInfo = GameInfo.DefaultGameInfo;
            var RatingResult = new RatingQuad();

            gameInfo.DrawProbability = drawPercentage / 100;

            Team team1 = new Team(player1, new Rating(homeMu, homeSigma, 3));
            Team team2 = new Team(player2, new Rating(awayMu, awaySigma, 3));

            int Param0 = 0;
            int Param1 = 0;

            int scoreR1 = homeScore;
            int scoreR2 = awayScore;

            if (scoreR1 > scoreR2)// Home win.
            {
                Param0 = 0;
                Param1 = 1;
            }
            else if (scoreR1 < scoreR2)// Away win.
            {
                Param0 = 1;
                Param1 = 0;
            }
            else if (scoreR1 == scoreR2)// Draw.
            {
                Param0 = 0;
                Param1 = 0;
            }
            //else
            //{
            //    MessageBox.Show("buttonCalculate_Click() Error: winType not recognised.");
            //}

            var newRatings = calc.CalculateNewRatings(gameInfo, Teams.Concat(team1, team2), Param0, Param1);

            foreach (KeyValuePair<Moserware.Skills.Player, Moserware.Skills.Rating> pair in newRatings)
            {

                if (pair.Key.ToString() == "1")
                {
                    RatingResult.homeMu = Convert.ToDouble(pair.Value.ToString().Split(',')[0].Split('=')[1]);
                    RatingResult.homeSigma = Convert.ToDouble(pair.Value.ToString().Split(',')[1].Split('=')[1]);
                }

                if (pair.Key.ToString() == "2")
                {
                    RatingResult.awayMu = Convert.ToDouble(pair.Value.ToString().Split(',')[0].Split('=')[1]);
                    RatingResult.awaySigma = Convert.ToDouble(pair.Value.ToString().Split(',')[1].Split('=')[1]);
                }

            }

            return RatingResult;

        }

    }

    public class RatingQuad
    {

        public double homeMu;
        public double homeSigma;
        public double awayMu;
        public double awaySigma;

    }//public class RatingQuad

}

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
if that solves the problem, grant points to sfaisalawan please and not to me, because he was much more a help than me :-). I was just *hopefully* nailing it down.