2 回答
TA贡献2041条经验 获得超4个赞
我通常做的是分配一个默认值 null 然后检查它是否为 null 并将其分配给一个新对象。类似于下面。
private LanDataEchangeWCF_Wrapper(
ILanDataEchangeWCFCallback callbackReciever = null,
bool cleanExistingConnection = true,
bool requirePingToKeepAlive = true,
int pingFrequency = 30000)
{
callbackReciever = callbackReciever ?? new LanCallBackDefaultHandler();
//Rest of constructor
}
TA贡献1828条经验 获得超3个赞
构造函数重载 ?
private LanDataEchangeWCF_Wrapper(bool cleanExistingConnection = true,
bool requirePingToKeepAlive = true,
int pingFrequency = 30000)
: this (new LanCallBackDefaultHandler(),
cleanExistingConnection,
requirePingToKeepAlive,
pingFrequency) {}
private LanDataEchangeWCF_Wrapper(ILanDataEchangeWCFCallback callbackReciever,
bool cleanExistingConnection = true,
bool requirePingToKeepAlive = true,
int pingFrequency = 30000)
{
if (cleanExistingConnection)
{
ExistingConnectionCleaner();
}
InitWs(callbackReciever);
if (requirePingToKeepAlive)
{
timer = new Timer(pingFrequency);
timer.Enabled = true;
timer.Elapsed += KeepAlive;
}
}
- 2 回答
- 0 关注
- 163 浏览
添加回答
举报