Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling Overloaded Constructors
Message
De
26/01/2006 00:59:52
 
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01090151
Message ID:
01090396
Vues:
10
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform