Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Constructor overloading
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00996906
Message ID:
00997047
Vues:
13
Chad,
Thank you for your reply. That was exactly my concern with using the constructor overloading. Great idea by calling a method from the constructor to handle the overloading issues. I do like overloading also, I find myself writing overload methods even when I don't think I will ever use more than the first overload method <s>

Again thanks for hanging in there with me until I was able to spit out the question :)

Sincerely,
Einar
>Einar,
>
>I happen to like overloading, but on something that might throw an exception, I would probably have another method (a set method perhaps) that stored the value the way I wanted it and optionally overload that method as well. That way, in this case anyway, I wouldn't need to have the constructors call each other. Something like this:
>
>private int someValue;
>
>public myConstructor(int para0)
>{
>  this.setValue(para0);
>}
>
>public myConstructor(string para0)
>{
>  this.setValue(para0);
>}
>
>public myConstructor(bit para0)
>{
>  this.setValue(para0);
>}
>
>public setValue(int para0)
>{
>  this.someValue = para0;
>}
>
>public setValue(string para0)
>{
>  try
>  {
>    this.someValue = para0.ToInt();
>  }
>  catch
>  {
>    this.someValue = 0;
>  }
>}
>
>public setValue(bit para0)
>{
>  this.someValue = (int)para0;
>}
>
>
>OR something like this:
>
>private int someValue;
>
>public myConstructor(int para0)
>{
>  this.setValue(para0);
>}
>
>public myConstructor(string para0)
>{
>  try
>  {
>    this.setValue(Int.Parse(para0).Value);
>  }
>  catch
>  {
>    this.setValue(0);
>  }
>}
>
>public myConstructor(bit para0)
>{
>  this.setValue((int)para0);
>}
>
>public setValue(int para0)
>{
>  this.someValue = para0;
>}
>
>
>Of course, you might want more error handling and I can't remember the right ways to parse ints right now, but I hope you get the jest of it.
>
>HTH,
>Chad
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform