C#中的继承问题:CS7036
由于某种原因,我在构造方法“修改后的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,构造仪有效地调用
:base()
在其基本类型上您有两个选项:
受保护的练习(){} {}
无参数构造函数:base(...)
明确指定要传递的值,在基本构造函数上的位置:2是通常的方法,用于减少重复。这也允许字段保留
私有
。By default constructors effectively call
: base()
on their base typeYou have two options here:
protected Exercise(){}
parameterless constructor to the base type: base(...)
explicitly specifying which value to pass in which position to the base constructorNote : 2 is the usual approach, to reduce duplication. This also allows the fields to remain
private
.