stupid question

  • Thread starter Thread starter Sebastian
  • Start date Start date
S

Sebastian

hello,

i think its a stupid question, but answer please. So how many params could i
use for the constructor new. My object or class has 24 properties. could i
init them using the constructor or is there a limit in params?

thanks in advance

sebastian
 
Sebastian said:
i think its a stupid question, but answer please. So how many params could i
use for the constructor new. My object or class has 24 properties. could i
init them using the constructor or is there a limit in params?

You could. If there *is* a limit (which there may be, I haven't
actually checked) it's much more likely to be something like 127, 255,
32767 or 65535.

You should think about the consequences of readability, however. I'd
find it much more readable to use separate initialisation of all of
those properties.
 
I honestly don't know if there is a limitation in the number of parameters you can pass, except limitations in stack size. Having said that I wonder if it is a good idea to have a constructor with that many parameters. Have you considered giving your properties a meaningfull default value and only setting those properties that are absolutely necessary from within a constructor? You could always provide set functions to actually set new property values

Regards
Maarten Struys, eMV
PTS Software b

----- Sebastian wrote: ----

hello

i think its a stupid question, but answer please. So how many params could
use for the constructor new. My object or class has 24 properties. could
init them using the constructor or is there a limit in params

thanks in advanc

sebastia
 
That's clear. But my objects are construct cause of database querys. So i
cant set a default and then only set the necessary one. I use the
constructor and not every set method of each property. i think its faster to
use the constructor. i hope there will be no stackoverflow. let's check
these thing.

regards

sebastian

Maarten Struys said:
I honestly don't know if there is a limitation in the number of parameters
you can pass, except limitations in stack size. Having said that I wonder if
it is a good idea to have a constructor with that many parameters. Have you
considered giving your properties a meaningfull default value and only
setting those properties that are absolutely necessary from within a
constructor? You could always provide set functions to actually set new
property values.
 
why don't you create an object e with all the properties
and pass it a single parameter?
sort of like is done with the EventArgs parameter in some circumstances.

Regards,

éric
 
Back
Top