C#中的继承问题:CS7036

发布于 2025-02-12 05:27:33 字数 2376 浏览 2 评论 0原文

由于某种原因,我在构造方法“修改后的ercise”中遇到错误 CS7036:没有任何参数对应于所需的正式参数name of coresoce.cortion.corcise(string,int,int,int,string,string,string [],dictionary&lt; string,bool&gt;)< /代码> 我添加了父级和子类练习修改exercise

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;
        }



    }
}

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;
        }



    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清晨说晚安 2025-02-19 05:27:33

默认情况下,构造仪有效地调用:base()在其基本类型上

您有两个选项:

  1. 到基本类型
  2. 添加受保护的练习(){} {}无参数构造函数 :base(...)明确指定要传递的值,在基本构造函数上的位置

:2是通常的方法,用于减少重复。这也允许字段保留私有

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文