Hi im getting a "An object reference is required for the non-static field, method, or property 'RealEstateSalesPerson.rate" error when i compile and i cant figure out how to fix it any help appreciated thx.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

    public interface ISell
    {
        string SalesSpeech();
        double MakeSale();
    }

    abstract public class SalesPerson : ISell
    {
        protected string firstName;
        protected string lastName;
        protected string fullName;

        public string FirstName
        {
            get
            {
                return firstName;
            }
        }
        public string LastName
        {
            get
            {
                return lastName;
            }
        }

        public string FullName
        {
            get
            {
                return fullName;
            }
        }
        public abstract string SalesSpeech();
        public abstract double MakeSale();
    }


    public class RealEstateSalesPerson : SalesPerson
    {

        double rate;
        public RealEstateSalesPerson(double rate)
        {
            string input;
            double rateE;

            Console.Write(" Please enter the real estate sales person's commission rate : ");
            input = Console.ReadLine();
            rateE = Convert.ToDouble(input);
        }





        private double valueSold = 0;
        public double ValueSold
        {
            get
            {
                return ValueSold;
            }
            set
            {
                valueSold = value;
            }
        }

        private double commission = 0;
        public double Commission
        {
            get
            {
                return Commission;
            }
            set
            {
                commission = value;
            }
        }

        public override string SalesSpeech()
        {
            return "Would you like to buy this amazing house for a very good price";
        }

        public override double MakeSale()
        {

           [U] double rate = RealEstateSalesPerson.rate;[/U]
            string value1;
            Console.Write("Please enter the amount of the sale :");
            value1 = Console.ReadLine();
            ValueSold += Convert.ToDouble(value1);
            Commission += ValueSold * rate;
            return Commission;



        }


        public class GirlScout : SalesPerson
        {
            private double boxesSold = 0;

            public double BoxesSold
            {
                get
                {
                    return BoxesSold;
                }
                set
                {
                    boxesSold = value;
                }

            }

            public override string SalesSpeech()
            {
                return "Would you like to buy some cookies";
            }

            public override double MakeSale()
            {
                string boxes;
                Console.Write("Please enter the amount of boxes sold :");
                boxes = Console.ReadLine();
                BoxesSold += Convert.ToDouble(boxes);
                return BoxesSold;
            }

        }



        public class salespersonDemo
        {
            public static void Main()
            {
                double iniRate = 0;
                RealEstateSalesPerson Real = new RealEstateSalesPerson(iniRate);
                GirlScout Ari = new GirlScout();


            }
        }
    }
double rate = RealEstateSalesPerson.rate;

RealEstateSalesPerson is a class, and to access non-static members of a class you need an instance of the class.

But you are in a method that is part of the class, so you can access members directly so this line does nothing for you. Remove it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.