2015-03-25 166 views
3
public class bar 
{ 
    public bar(list<int> id, String x, int size, byte[] bytes) 
    { 
    ... 
    } 
} 

public class Foo: Bar 
{ 
    public Foo(list<int> id, String x, someEnumType y): 
    base(id, x, sizeof(someEnumType), y) 
    { 
     //some functionality 
    } 
} 

正如您在上面的代码中看到的,我需要在调用基类构造函数之前将someEnumType转换为字节数组类型。有没有办法做到这一点?喜欢的东西:在派生类中调用基类构造函数

public class Foo: Bar 
{ 
    public Foo(list<int> id, String x, someEnumType y) 
    { 
     //someEnumType to byte array 
     base(...) 

    } 
} 

回答

4

在派生类中只需创建一个方法,并调用它....

public class bar 
{ 
    public bar(list<int> id, String x, int size, byte[] bytes) 
    { 
    ... 
    } 
} 

public class Foo: Bar 
{ 
    public Foo(list<int> id, String x, someEnumType y): 
    base(id, x, sizeof(someEnumType), Convert(y)) 
    { 
     //some functionality 
    } 

    public static byte[] Convert(SomeEnumType type) 
    { 
     // do convert 
    } 
} 
+0

u的权利..我更新的答案 – puko 2015-03-25 10:23:36

相关问题