C# 在具有多个构造函数的单个类中使用对象

C# 在具有多个构造函数的单个类中使用对象,c#,class,oop,constructor,xna,C#,Class,Oop,Constructor,Xna,这是我在其中构建构造函数的类,我希望有多个“UserKeys”构造函数,在我的项目中每个字符1个,但是主类不识别第二个构造函数,而只识别第一个(如果我有一个接受0个参数的构造函数,它会识别它和第一个,但不会识别第二个) 两个构造函数都有相同的参数,这不起作用。只是他们的名字不同。你需要让他们与众不同: public UserKeys(Keys left, Keys right, Keys up, Keys down, Keys h

这是我在其中构建构造函数的类,我希望有多个“UserKeys”构造函数,在我的项目中每个字符1个,但是主类不识别第二个构造函数,而只识别第一个(如果我有一个接受0个参数的构造函数,它会识别它和第一个,但不会识别第二个)


两个构造函数都有相同的参数,这不起作用。只是他们的名字不同。你需要让他们与众不同:

public UserKeys(Keys left, Keys right,
                Keys up, Keys down, 
                Keys high_hit)
{
    this.left = left;
    this.right = right;
    this.up = up;
    this.down = down;
    this.high_hit = high_hit;
}

public UserKeys(Keys left, Keys right, 
                Keys up, Keys down, 
                Keys high_hit, Keys walk)
{
    this.left = left;
    this.right = right;
    this.up = up;
    this.down = down;
    this.high_hit = high_hit;
    this.walk = walk;
}

我已经将
键添加到第二个
,并且使用了与第一个相同的顺序(否则会非常混乱和容易出错)。如果您不知道
向上键
传递
键。无

什么是“识别”,您会得到一个编译器错误?如果是,告诉我们。主类中使用构造函数的代码是什么?两个构造器都有相同的参数,这不起作用。你是什么意思:“我想有多个“用户密钥”构造器,每个字符1个”?我有几个字符,蝙蝠侠、亚零超人和flash。我想在用户密钥中为每个从键盘上获取不同密钥的角色设置构造函数,例如,我想通过单击f来选择超人飞行,但flash不需要这个函数,所以我想在UserKeys类中有一些构造函数选项,这样我就不需要给一个字符赋值了,我用他不用的键盘来构建键。在我的主类中,我所做的就是创建新的UserKeys对象,我想给它键盘键(例如:上、下、右、左、'Z'、'X')
public UserKeys(Keys left, Keys right,
                Keys up, Keys down, 
                Keys high_hit)
{
    this.left = left;
    this.right = right;
    this.up = up;
    this.down = down;
    this.high_hit = high_hit;
}

public UserKeys(Keys left, Keys right, 
                Keys up, Keys down, 
                Keys high_hit, Keys walk)
{
    this.left = left;
    this.right = right;
    this.up = up;
    this.down = down;
    this.high_hit = high_hit;
    this.walk = walk;
}