C# Flashcards
(24 cards)
True or false: You can convert a bool to an int
False
Which type of object holds the actual data?
Value
Which type of object holds only a reference to the data?
Reference
How do you create a nullable value type?
Appending a ? to the
What can you do to reduce the amount of code you have to write when using a namespace?
Add the using keyword with the namespace as a top-level statement.
Can an abstract class be instantiated?
No
What makes a record different from a class is that the equality between objects means…
All of the types, properties and field values match.
Equality between two class objects means…
The two objects are the same object.
C# does not allow multiple inheritance. What can you use to mimic that behavior?
Interface
C# delegates is what and how do they compare to JS callbacks?
It is a type that stores a function pointer. It can be used to create callbacks but is not its only function.
Converting from a value type to a reference type is called…and conversion is…
Boxing
Converting from a reference type to a value type is called…and conversion is…
Unboxing explicit conversion (cast)
The main difference between string and stringbuilder is what? When would you use one over the other?
if a string is changed it creates a new instance whereas stringbuilder modifies the same instance. Use stringbuilder when performance is favored. (Large loops)
What is a sealed class?
A class that can not be inherited from.
What is a partial class?
A class that is defined into segmented parts within the same file or different files.
A constant can never be changed, when can a readonly be changed?
Only in a non-static constructor.
When does a ref get initialized? When does an out?
Ref get’s initialized before a method gets called where an out get’s initialized within the method. out for out only
Extension methods are a way to add to what?
An existing class library without modifying the original type definition class. Ex. Adding a method to the int class.
Early Binding Polymorphism has the overridden methods where? What conditions must be met?
In the same class definition. It is required that the methods have different signatures such as different number of parameters or different order of parameters.
Late Binding Polymorphism has the overridden methods where? What conditions must be met?
In the inherited classes. We would declare the method as virtual and override them in any way we want to in the inherited class. The signatures can be identical in this case.
What makes an indexer different from a property?
Indexers use the this keyword so that the object can be treated as an array. (From my understanding, creating a property that has an array type adds one word to code so this is kind of dumb)
Name the three main access modifiers.
public, private, protected
What is the most basic definition of serialization?
Converting an object to a stream of bytes.
What is a simple way to describe a jagged array?
An array of arrays.