Shared Constructors

Classes can implement shared constructors, as shown in the following code:

image

Shared constructors are particularly useful for initializing shared members or for loading data that is common to all instances of a class; a shared constructor is invoked immediately before the normal constructor that creates a new instance of the class. With that said the following code is appropriate and accepted by the compiler:

image

Another important thing to take care of is that shared constructors have Private visibility and they are the only point in the class in which you can initialize a read-only field.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.167.114