C# language
Terms
undefined, object
copy deck
- What are the two Types in C#?
- Reference Type, Value Type
- What type is stored in the Heap and what value type is stored in the stack?
-
Heap: Reference
Stack: Value - What is a class Destructor?
- Method called by the garage collector to remove a object form managed memory.
- Can a class Destructor be called like other methods ?
- No the Destructor can only be called by the Garbage collector.
- What does the Destructor and Finalize() have in commen ?
- The destructor method is a short cut to creating a overridden finalize method.
- What is the Using key word for?
- The Using statement ensures that the Dispose() method will be called at the earliest opportunity.
- What is the IDespose Interface for?
- The IDespose method will handle memory cleanup considered to crucial to wait for the garbage collector.
- What is Polymorphism ?
- The ability to use many forms of a type with out regard to the implementation details.
- What is Boxing and Unboxing Types?
-
The process by which value types (int, float, ... ect) can be treated as reference types.
example:
int y = 3;
object x = y; - What does an Interface represent?
- An interface represents a contract that guaranties to a client how a class or Struct will behave.
- What are internal classes and why are they useful?
-
one example is a class that is created within another class and is marked as "internal".
In this way an internal class can access the private member if the class it is within. -
What do Classes and Structs have in common?
What is Different? -
a: Structs and Classes both have constructors, properties, methods, fields, operators, nested types, and indexers.
b: Structs don't have inheritance, destructors, and are a value type not a reference type. - Finalize()
- Cleans up any non memory resources. Implemented by the Destructor.
- When do you have to explicitly override the Destructor?
- When unmanaged resources need to be freed.
- What does "ref" key word used for ?
- Used to signify a pass by reference for method parameters.
-
What will the following code snippet produce?
public void updateInt( int x)
{x+= 1;}
int x=0;
updateInt(x);
Console.WriteLine(x); - answer: 0;
- What is the Difference between the key word 'is' and the 'as' ?
-
Is returns true if two object types match.
AS returns the the object if types match.
example: is
if ( someObj is someOtherObj )
{
// do some code
}
example as:
someObj obj as someOtherObj someObj;
if ( obj != null)
// do some code; - What is Reflection in C#?
- The ability to view and interact with an objects metadata.
- Four major tasks reflection is used for?
-
1. viewing metadata
2. Perform type discovery.
3. Late binding to methods and properties.
4.Creating types at runtime.