AppXmlLogWritter objParameterized = new AppXmlLogWritter(1234, "LogApplication", "LogFilepath");
AppXmlLogWritter objParmeterlessConstr = new AppXmlLogWritter();
objParameterized.WriteXmlLog("0", "LogFlag");
如何獲取此函數中的默認構造函數值?如何獲取函數中的默認構造函數值
AppXmlLogWritter objParameterized = new AppXmlLogWritter(1234, "LogApplication", "LogFilepath");
AppXmlLogWritter objParmeterlessConstr = new AppXmlLogWritter();
objParameterized.WriteXmlLog("0", "LogFlag");
如何獲取此函數中的默認構造函數值?如何獲取函數中的默認構造函數值
調用構造如下圖所示,通過這個()
public AppXmlLogWritter(int intLogIDPrefix, string strLogApplication, string strLogFilePath)
:this()
{
LogIDPrefix = intLogIDPrefix;
LogApplication = strLogApplication;
LogFilePath = strLogFilePath;
}
不是很清楚你說的是什麼價值,但是如果你參考randomNumber
,你已經有了在類裏面。
如果你要調用的函數是消耗型AppXmlLogWritter
的功能,你可以這樣定義屬性:在您的其它構造
public class AppXmlLogWritter{
public int RandomNumber {get;set}; //PUBLIC PROPERTY
public AppXmlLogWritter()
{
Random random = new Random();
RandomNumber = random.Next(9999);
LogDateTime = DateTime.Now.ToString("yyyyMMdd HHmmss");
}
.... ..
.... ..
}
從另一個構造函數調用類的基類的構造使用this
關鍵字,像這樣:
public AppXmlLogWritter(int intLogIDPrefix, string strLogApplication, string strLogFilePath)
: this()
{ ... }
怎麼樣日期時間我也得到日期時間功能空白 – lax
@如果你的問題是你的默認ctor沒有被調用,只需添加'this()'參數化ctor的聲明。 – Tigran