将什么作为字符串参数传递给构造函数?

时间:2014-04-14 08:42:51

标签: c#

我有以下情况:

protected MobileWalletRequestBase(XmlDocument xmlDoc, string request)
{
    _xmlDoc = xmlDoc;
}

protected MobileWalletRequestBase()
    : this(new XmlDocument(), ?)
{
    _xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><request/>");
}

我应该在第二个构造函数中写什么才能传递字符串值?

1 个答案:

答案 0 :(得分:1)

一种方法是使用默认参数:

protected MobileWalletRequestBase(XmlDocument xmlDoc, string request="foo")
{
    // but you're not using request in here, unclear what's needed
    _xmlDoc = xmlDoc;  
}

protected MobileWalletRequestBase()
    : this(new XmlDocument())   // don't say anything
{
    _xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><request/>");
}