Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling Overloaded Constructors
Message
From
26/01/2006 00:59:52
 
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01090151
Message ID:
01090396
Views:
11
This message has been marked as a message which has helped to the initial question of the thread.
You have to rewrite. Anything in the parameter list runs first. Meaning the call to the 1st constructor will run before the code in the second constructor.

>Hi all,
>
>Here's a snippet from a class I'm writing:
>
>        public jsEventLog(bool logInit) : this()
>        {
>            if (logInit)
>            {
>                this.WriteEntry("Event log object has been initialized.");
>            }
>        }
>
>        public jsEventLog(string source) : this(true)
>        {
>            this.Source = source;
>        }
>
>The idea is to be able to instantiate this class with a string and have it log an initialized message automatically. The WriteEntry method has several overloads, and using the one above defaults the source to the this.Source value. The problem is that when the 2nd constructor is called (by instantiation), it calls the 1st constructor before it runs the code within the 2nd constructor. Is there a way to change that order or do I have to rewrite my methods in such a way that all my methods will work with that ordering?
>
>TIA,
>Chad

(On an infant's shirt): Already smarter than Bush
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform