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");
如何在此函数中获取默认构造函数值?
通过 this() 在你的其他构造函数中调用构造函数,如下所示
public AppXmlLogWritter(int intLogIDPrefix, string strLogApplication, string strLogFilePath)
:this()
{
LogIDPrefix = intLogIDPrefix;
LogApplication = strLogApplication;
LogFilePath = strLogFilePath;
}
要从另一个构造函数调用类的基本构造函数,请使用如下this
关键字:
public AppXmlLogWritter(int intLogIDPrefix, string strLogApplication, string strLogFilePath)
: this()
{ ... }
不太清楚你在说什么价值,但如果你提到randomNumber
,你已经在课堂上对它进行了访问。
如果您要调用的函数是使用 type 的函数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");
}
.... ..
.... ..
}