Study your flashcards anywhere!

Download the official Cram app for free >

  • Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key


Play button


Play button




Click to flip

17 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)
What are the three kinds of class constructors?
What is the function of an 'instance' constructor?
To create and initialize instances of a class.
What is the function of a private constructor?
Used to create a class that cannot be instantiated. Typically these are classes containing only static members. Use of a private constructor prevents C# from invoking the default constructor.
Can a class with a private constructor be inherited?
Can a private class be used in a declaration?
privateConstructorClass foo;
What might a class with a private constructor be used for?
A good use for a private constructor class is to encapsulate a bunch of related constants.
What is the purpose of a 'static' constructor?
A static constructor, like a class constructor, is usd to initialize an instance of a class. However, it is called by the system before the first instance of the class is created.
Show an example of a static constructor?
public class myClass
static myClass()

Note: since static constructors are not called directly they do not have access modifiers.
What are the three major differences between a class constructor and a struct constructor?
1. Cannot contain parameterless constructors.
2. Members initialized to default values
3. Cannot use "base" initializers
Will the following declaration compile:
public struct foo
int[] bar = new int[3];
No. You will receive the following error message:
'': cannot have instance field initializers in structs
What is the purpose of a destructor?
Destructors are used to destroy an instance of a class.
How is a destructor declared?
precede the class name with a tilde:

class foo
~foo(){ <some code> }
How is a destructor called?
A destructor cannot be called directly. It is invoked automatically by the garbage collector.
What method is called by the destructor even if you do not explicitly invoke it?
The base objects Finalize() method.
How do you force a garbage collect?
invoke the
GC.Collect method.

This is not recommended because it may result in poorer performance than the .NET garbage collection algorthm.
Why might you want to create a destructor?
1. To release resources being used by unmanaged code
2. To release a valuable/scarce external resource.
What method must you use to cleanup external resource references?
You must implement a 'Dispose' method that is inherited for the 'IDisposable' interface.