vb.net - When should I use multiple constructors? -


what difference between these 2 options?

first option - multiple constructors

public sub new(some parameters)     'do somthing end sub  public sub new(other parameters)     'do end sub 

in case, use multiple constructors different parameters in order initialize different objects or create instance of class in different ways.

second option - using optional parameters

public sub new(optional values)     'do end sub 

in case, use optional parameters when want assign them.by using method can control objects want initialize or create instance of them.

in first case, using method overloading invoke different functionality in different constructors based on method signature. functionality might include allowing parameters assume default values.

using optional parameters more appropriate in constructor when only want parameters optional , you're not looking invoke different functionality in constructor, other allowing parameters set default if don't supply them.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -