小编Cor*_*ern的帖子

派生类的C#错误

我有一个基类:

public class Base {
  public string Foo { get; set; }
  public float Bar { get; set; }
  public float Foobar { get; set; }

  public Base (string foo, float bar, float foobar) {
      Foo = foo;
      Bar = bar;
      Foobar = foobar;
  }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试添加扩展此类的类时,我收到错误:

public class Derived : Base {
    public Base derived = new Derived ("Foo", 0f, 0f);
}
Run Code Online (Sandbox Code Playgroud)

收到的错误说明如下: Base does not contain a constructor that takes 0 arguments

我在Derived类的第1行得到了这个错误.任何修复/原因导致这种情况发生?

c# unity5

0
推荐指数
1
解决办法
67
查看次数

标签 统计

c# ×1

unity5 ×1