Re: Named parameters?
- From: "Daniel O'Connell [C# MVP]" <onyxkirx@xxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 9 May 2005 13:19:07 -0500
"Ben R." <BenR@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:01F6D0AC-4A3F-4BF4-8162-651B8763A73F@xxxxxxxxxxxxxxxx
> I'm reading about attribute classes and specifically, named versus
> positional
> parameters. Was this implimented instead of multiple constructors for
> flexibility or is there another reason I'm missing?
>
It is flexibility more than anything else, I think. Considering the sets of
options an attribute has, multiple constructors would be complicated to say
the least, if not impossible. Named parameters are really no different than
the standard:
X x = new X();
x.Property = 10;
except that they have to be written in a more condensed form.
Consider you have two properties of type string, Name and Description
If you only want to set one of those, assuming the attribute doesn't require
both in the constructor, of course, you can. But if you use multiple
constructors there is no way to define a set of two constructors that will
allow you to set one and only one of the above properties.
Now, consider if you had 20 properties, the chances of being able to
generate all the possible combonations of properties in the constructor are
very very low, its likely you will run into the same problem somewhere. Not
to mention the hideous number of constructors.
.
- Follow-Ups:
- Re: Named parameters?
- From: Ben R.
- Re: Named parameters?
- References:
- Named parameters?
- From: Ben R.
- Named parameters?
- Prev by Date: Re: Is this good use of Properties?
- Next by Date: "Add Inherited Form" Missing from Visual C# Express Beta 2?
- Previous by thread: Named parameters?
- Next by thread: Re: Named parameters?
- Index(es):
Relevant Pages
|