Re: Named parameters?

Tech-Archive recommends: Fix windows errors by optimizing your registry




"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.


.



Relevant Pages

  • Re: Named parameters?
    ... There are already suggestions made to microsoft to include named parameters ... Was this implimented instead of multiple constructors for ... multiple constructors would be complicated to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Setting readonly variables
    ... > Where I have had multiple constructors for a class I have had to apply all ... > public MyClass(string name, string address) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Named parameters?
    ... settable in a named parameter or could one do the same with a public field? ... Was this implimented instead of multiple constructors for ... > It is flexibility more than anything else, ... multiple constructors would be complicated to say ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: JarFile/ZipFile from byte array without temp file
    ... reading it back via the JarFile/ZipFile constructors?? ... forget byteand/or stream constructors? ... Probably because those classes are specific to reading from FileInputStreams? ...
    (comp.lang.java.programmer)
  • Re: Where to put user interface
    ... > constructors to get the data needed to build an object. ... the students get this information from? ... create a second assignment where they have ... reading is done in a seperate function). ...
    (alt.comp.lang.learn.c-cpp)