0
AppXmlLogWritter objParameterized = new AppXmlLogWritter(1234, "LogApplication", "LogFilepath");

AppXmlLogWritter objParmeterlessConstr = new AppXmlLogWritter();

objParameterized.WriteXmlLog("0", "LogFlag");

如何在此函数中获取默认构造函数值?

4

3 回答 3

3

通过 this() 在你的其他构造函数中调用构造函数,如下所示

    public AppXmlLogWritter(int intLogIDPrefix, string strLogApplication, string strLogFilePath)
          :this()
    {
        LogIDPrefix = intLogIDPrefix;
        LogApplication = strLogApplication;
        LogFilePath = strLogFilePath;
    }
于 2012-10-14T09:38:25.467 回答
2

要从另一个构造函数调用类的基本构造函数,请使用如下this关键字:

public AppXmlLogWritter(int intLogIDPrefix, string strLogApplication, string strLogFilePath) 
    : this()
{ ... }
于 2012-10-14T09:38:55.993 回答
0

不太清楚你在说什么价值,但如果你提到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");
        }

     .... ..
     .... ..       

}
于 2012-10-14T09:33:24.830 回答