Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Inheritance Issue in C# : CS7036

For some reason I’m getting an error in the constructor method "ModifiedExercise"
CS7036: There is no argument given that corresponds to the required formal parameter name of Exercise.Exercise(string,int,int,string,string[],Dictionary<string,bool>)
I added the Parent and child classes Exercise and ModifiedExercise.

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

namespace Trainer_App
{
    internal class ModifiedExercise : Exercise 
    {
        private Exercise regular_exercise;
        public ModifiedExercise(Exercise regular_exercise,
                                string name,
                                int min_num_balls,
                                int participants_num,
                                string court_type,
                                string[] accessories,
                                Dictionary<string, bool> exerciseTypes)
        {
            this.regular_exercise = regular_exercise;
            this.id = Exercise.id_counter;
            Exercise.id_counter++;
            this.name = name;
            this.min_num_balls = min_num_balls;
            this.participants_num = participants_num;
            this.court_type = court_type;
            this.accessories = accessories;
            this.exerciseTypes = exerciseTypes;

        }
    }
}

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

namespace Trainer_App
{
    internal class Exercise
    {
        protected static int id_counter = 0;
        protected int id;
        protected string name;
        protected int min_num_balls;
        protected int participants_num;
        protected string court_type;
        protected string[] accessories;
        protected static int exerciseCounter = 0;
        protected Dictionary<string, bool> exerciseTypes = new Dictionary<string, bool>();

        public Exercise(string name,int min_num_balls, int participants_num,string court_type, string[]accessories,Dictionary<string,bool> exerciseTypes)
        {
            this.id = id_counter;
            id_counter++;
            this.name = name;
            this.min_num_balls = min_num_balls;
            this.participants_num = participants_num;
            this.court_type = court_type;
            this.accessories = accessories;
            this.exerciseTypes = exerciseTypes;
        }



    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

By default constructors effectively call : base() on their base type

You have two options here:

  1. Add a protected Exercise(){} parameterless constructor to the base type
  2. Add an explicit : base(...) explicitly specifying which value to pass in which position to the base constructor

Note : 2 is the usual approach, to reduce duplication. This also allows the fields to remain private.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading