在派生构造函数中的某个代码块之后调用派生 class 中的基础 class 构造函数
Calling a base class constructor in derived class after some code block in derived constructor
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
}
}
正如您在上面的代码中看到的,我需要在调用基础 class 构造函数之前将 someEnumType 转换为字节数组类型。有办法吗?类似于:
public class Foo: Bar
{
public Foo(list<int> id, String x, someEnumType y)
{
//someEnumType to byte array
base(...)
}
}
只需在派生的 class 中创建一个方法并调用它....
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
}
}
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
}
}
正如您在上面的代码中看到的,我需要在调用基础 class 构造函数之前将 someEnumType 转换为字节数组类型。有办法吗?类似于:
public class Foo: Bar
{
public Foo(list<int> id, String x, someEnumType y)
{
//someEnumType to byte array
base(...)
}
}
只需在派生的 class 中创建一个方法并调用它....
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
}
}