2012-10-14 133 views
0
AppXmlLogWritter objParameterized = new AppXmlLogWritter(1234, "LogApplication", "LogFilepath"); 

AppXmlLogWritter objParmeterlessConstr = new AppXmlLogWritter(); 

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

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

回答

3

调用构造如下图所示,通过这个()

public AppXmlLogWritter(int intLogIDPrefix, string strLogApplication, string strLogFilePath) 
      :this() 
    { 
     LogIDPrefix = intLogIDPrefix; 
     LogApplication = strLogApplication; 
     LogFilePath = strLogFilePath; 
    } 
0

不是很清楚你说的是什么价值,但是如果你参考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"); 
     } 

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

} 
+0

怎么样日期时间我也得到日期时间功能空白 – lax

+0

@如果你的问题是你的默认ctor没有被调用,只需添加'this()'参数化ctor的声明。 – Tigran

2

从另一个构造函数调用类的基类的构造使用this关键字,像这样:

public AppXmlLogWritter(int intLogIDPrefix, string strLogApplication, string strLogFilePath) 
    : this() 
{ ... }