Chapter 5 – Building Your Own Types with ObjectOriented Programming Flashcards
What are the six combinations of access modifier keywords and what do they do?
The six combinations of access modifier keywords and their effects are described in
the following list:
* private: This modifier makes a member only visible inside the class.
* internal: This modifier makes a member only visible inside the same assembly.
* protected: This modifier makes a member only visible inside the class or derived
classes.
* internal protected: This modifier makes a member only visible inside the class,
derived classes, or within the same assembly.
* private protected: This modifier makes a member only visible inside the class or
derived classes that are within the same assembly.
* public: This modifier makes a member visible everywhere.
What is the difference between the static, const, and readonly keywords when applied to
a type member?
The difference between the static, const, and readonly keywords when applied to
a type member is described in the following list:
* static: This keyword makes the member shared by all instances and it must be accessed
through the type, not an instance of the type.
* const: This keyword makes the field a fixed literal value that must never change because during the compilation, assemblies that use the field copy the literal value at
the time of compilation.
* readonly: This keyword restricts the field so that it can only be assigned to using a
constructor or field initializer at runtime.
What does a constructor do?
A constructor allocates memory and initializes field values.
Why do you need to apply the [Flags] attribute to an enum type when you want to store combined values?
If you don’t apply the [Flags] attribute to an enum type when you want to store combined values, then a stored enum value that is a combination will be returned by a call to
ToString as the stored integer value, instead of one or more of the comma-separated list of
text values.
Why is the partial keyword useful?
You can use the partial keyword to split the definition of a type over multiple files.
What is a tuple?
A tuple is a data structure consisting of multiple parts. They are used when you want
to store multiple values as a unit without defining a type for them.
What does the record keyword do?
The record keyword defines a data structure that is immutable by default to enable a
more functional programming style. Like a class, a record can have properties and methods,
but the values of properties can only be set during initialization.
What does overloading mean?
Overloading is when you define more than one method with the same method name
and different input parameters.
What is the difference between a field and a property?
A field is a data storage location that can be referenced. A property is one or a pair of
methods that get and/or set a value. The value of a property is often stored in a private field.
How do you make a method parameter optional?
You make a method parameter optional by assigning a default value to it in the method
signature.