Notes

1) What is the difference between Value data types and Reference data types ?

A value type is also known as a primitive or simple type.
When a value data type is created, a single space in memory is allocated on the stack and is accessed directly.
Value data types are automatically given a default value of zero (or equivalent) when they are declared.
A reference type is also known as an object type.
When a reference data type is created, memory is allocated on the heap and is not accessed directly. Instead a pointer to the memory location is used.
Reference data types are automatically given a default value of null when they are declared.


2) Can you explain the difference between the Stack and the Heap ?

The stack contains value data types on a first in, first out basis.
The heap contains reference data types.


3) Can you give some examples of Value data types ?

struct 
enMyCities
System.Byte
System.Decimal
System.Double
System.Single
System.Int16
System.Int32
System.Int64
System.DateTime
System.Windows.Forms.Point


4) Can you give some examples of Reference data types ?

class 
interface
System.String
System.Object
System.Delegate
System.Array
System.Tuple


5) What .NET data types do the following keywords map to ?

short - System.Int16 
int - System.Int32
long - System.Int64
float - System.Single
decimal - System.Decimal
double - System.Double
int[] float - System.Int32[]


6) Can you identify the underlying .NET data type of a variable or object at run-time ?

Yes. The run-time data type can be found using the GetType method.
You cannot use the GetType method in conjunction with COM Interop.
The data type returned for all COM Interop objects is "System._ComObject".

if (variable.GetType().FullName == "System.Int32" ) 
if (variable.GetType() == typeof(System.Int32) )


7) Can you identify the underlying COM Interop data type of a variable or object at run-time ?

Yes. The run-time data type can be found using either the 'is' operator or the 'as' operator.

if (myObject is Excel.Range) 

Excel.Range myRange = myObject as Excel.Range
if (myRange != null)


8) What is the 'typeof' Operator ?

This operator ??

System.Type MyType = typeof(int); 


9) Is there any difference between the following lines of code ?

int myValueType = 20; 
MessageBox.Show(myValueType.GetType().Name)
MessageBox.Show(myValueType.GetType().FullName)
MessageBox.Show(myValueType.GetType().ToString())

Name displays "Int32"
FullName displays "System.Int32"
ToString displays "System.Int32"


10) Is there any difference between the following lines of code ?

string[] myReferenceType = new string[] {"Mon", "Tue", "Wed"}; 
MessageBox.Show(myReferenceType.GetType().Name)
MessageBox.Show(myReferenceType.GetType().FullName)
MessageBox.Show(myReferenceType.GetType().ToString())

Name displays "String"
FullName displays "System.String[]"
ToString displays "System.String[]"


11) Can you convert a Value data type to a Reference data type ?

Yes. Value data types can be converted to objects. This is called Boxing.
Boxing is encapsulating a copy of a value data type into an object.

int myNumber = 5; 
object MyObject1 = myNumber; // implicit boxing
object MyObject2 = (object)myNumber; // explicit boxing
object MyObject3 = myNumber as object; // explicit boxing


12) Can you convert a Reference data type to a Value data type ?

Yes. Reference data types can be converted into value data types. This is called Unboxing.

string MyText = "text"; 
object MyObject = (object)MyText;
string MyText1 = (string)MyObject; // explicit unboxing ???? (string)
string MyText2 = MyObject as string; // explicit unboxing


13) What is a Literal Number Suffix ?

Also known as numeric literal suffixes.
In most cases the compiler is able to determine the correct data type for a numerical literal however there might be times when the default data type is different to the desired one.
In these cases a suffix can be added to explicitly tell the compiler which data type you want to use.

myNumber = 10000000F  //float = System.Single 
myNumber = 10000000U //uint = System.UInt32
myNumber = 10000000L //long = System.Int64
myNumber = 10000000UL //ulong = System.UInt64
myNumber = 10000000M //decimal = System.Decimal


14) What are Nullable data types ?

These are Value data types that can be assigned a null value. This does not affect the default value).
They represent all the values of their underlying data type plus the additional null value.

int? myNumber = null; 
System.Nullable<int> myNumber = null;

Each instance of a nullable data type has two public read-only properties.
*) HasValue - returns true if the variable contains a non-null value.
*) Value - should only be accessed when HasValue is true.

int? myNumber = null; 
myNumber = 50
if (myNumber.HasValue == true)
{
   MessageBox.Show(myNumber.Value);
}


15) Can you explain the following lines of code ?

int? myNumber = null; 
long myReturn;
myReturn = myNumber ?? 20.5;

The nullable coalescing operator (??) can be used to provide an alternative value when a variable is null.
This operator works with both value and reference data types.

System.Array myArray; 
long myReturn;
myReturn = myArray ?? 20.5;

An array variable is declared with an initial default value of null.
A long variable is declared with an initial default value of zero.
The long variable is then assigned the value 20.5 because the myArray variable is null.


16) Can you explain the following lines of code ?

int myNumber = 10; 
myNumber += DateTime.Today.Day;
MessageBox.Show(myNumber);

An integer variable is declared and is assigned the value 10.
The addition self-assignment operator (+=) adds the numerical day of the month to the value 10.
This total is then displayed in a message box.


17) Can you convert an integer data type to a string data type ?

Yes. There are a numerous ways this can be done.

int i = 10; 
string s;
s = i.ToString()
s = System.Convert.ToString(i);
s = System.String.Format("{0}",i);
s = $"{i}";
s = "" + i
s = System.String.Empty + i
s = new System.Text.StringBuilder().Append(i).ToString();


18) What is Casting ?

Casting is the name used to describe an explicit data type conversion.
This has nothing to do with boxing or unboxing.

long myLarger = 500000; 
int mySmaller;
mySmaller = (int)myLarger;


19) What is the difference between a Literal constant and a Symbolic constant ?

A literal constant is a specific value such as a number, boolean, date, text.

bool myBoolean = false; 

A symbolic constant is a literal constant that is represented by a name.

public const string myText = "text"; 


20) Can you have a DateTime Literal constant in C# ?

C# does not support date or time literal constants (however VB.Net does).
A date and time literal constant must be declared using the System.DateTime class.

System.DateTime myDate = new System.DateTime(1900, 1, 1); 


21) Can you define a String constant that can be accessed anywhere ?

public class MyConstants 
{
   static const string MyText = "hello";
}


22) What is an Enumeration ?

An Enumeration provides a way of grouping symbolic constants.
The default data type is System.Int32.
The first item in an enumeration has a value of 0.
An enumeration is a value type.


23) Can you define an Enumeration that contains two cities ?

The default access modifier for an enumeration is public.

public enum enMyCities 
{
    london = 1,
    tokyo = 2
};


24) Is it possible to return the string names instead of the numbers from an Enumeration ?

Yes.

int myValue = enMyCities.tokyo; 
string MyText = System.Enum.GetName(typeof(enMyCities), myValue);


25) What is an Immutable data type ?

This is a type of object whose value or state cannot be changed after it has been created.
The System.String is an immutable data type so every time the value is modified a new instance is created.

System.String myText = "some text"; 
myText = myText.Replace("e","a");


26) What is the difference between System.String and System.Text.StringBuilder ?

StringBuilder is mutable and is more efficient when a lot of string manipulations are required.
Strings are immutable.

System.Text.StringBuilder myStringBuilder; 
myStringBuilder = new System.Text.StringBuilder("some text");
myStringBuilder.Append("more");
myStringBuilder.Replace("e","a");


27) Describe the 'System.Tuple' data type ?

This is a data structure that has a specific number of elements and a sequence.
This data type directly supports up to seven elements.
This is a reference type.

System.Tuple <int, string, bool> MyTuple; 
MyTuple = new System.Tuple<int, string, bool>(0, "text", false);


28) What does Strongly Typed mean ?

A programming language is strongly typed if there are no implicit type conversions.
A strongly-typed programming language is one in which each data type is predefined as part of the programming language and all constants or variables must be defined with a specifc data type.
An advantage of strong data typing is that it imposes a rigorous set of rules on a programmer and therefore guarantees a certain consistency of results.


29) Is C# a Strongly Typed programming language ?

Yes. C# and VB.Net are both strongly typed languages.


30) What is the difference between Procedural and Object Orientated programming ?

Procedural is based in a modular approach where a larger program is broken up into smaller procedures or functions.
Each procedure has a set of instructions that is executed one after another.
Access modifiers are not used in procedural programming which means that most of the code can be accessed from anywhere.


31) Is an Array a value data type or a reference data type ?

All arrays are reference data types.
They are implicitly derived from System.Array which is derived from System.Object.

string[] myArray = new string["Mon","Tue","Wed"]; 
MessageBox.Show(myArray.GetType().FullName);

This displays "System.String[]".


32) What is the difference between an Array and a Collection ?

Arrays are strongly typed collections of the same data type that have a fixed length that cannot change at run-time.
Collections are not strongly types and can store different data types which are dynamic in size.


33) Can you give some examples of different types of Collections ?

System.Collections.ArrayList 
System.Collections.Generic.List
System.Collections.Generic.Dictionary
System.Collections.Generic.KeyValuePair


34) Can you create a list / collection containing the values 1,2,3 ?

System.Collections.Generic.List<int>MyList; 
MyList = new System.Collections.Generics.List<int>();
MyList.Add(1);
MyList.Add(2);
MyList.Add(3);
MyList = new System.Collections.Generics.List<int> {1,2,3};


35) How would you declare a 2 dimensional Integer Array ?

int[ , ] myArray; 


36) What is the difference between a Rectangular Array and a Jagged Array ?

A rectangular array has the same dimensions and sizes.

string[, , ,] myArray; 

A jagged array can have different dimensions and sizes. Also called an array or arrays.

string[][][] myArray; 


37) What is the difference between a deep copy and a shallow copy ?

A deep copy copies across Reference data types and Value data types. All the elements into another already existing array.

System.Array.CopyTo    // deep copy 

A shallow copy copies across Value data types. Create a new array object containing all the elements

System.Array.Clone    // shallow copy 


38) Write a For loop to display the values in a list ?

for (int count = 0; I < MyList.Length; i++) 
{
    MessageBox.Show(MyList[count]);
}


39) Write a For-Each loop to display the values in a list ?

foreach (int myNumber in MyList) 
{
    MessageBox.Show(myNumber);
}


40) Can you describe the purpose of a Try-Catch-Finally block ?

The try block encloses those statements that might cause an exception.
The catch block can handle exceptions.
The finally block always executes and contains any cleanup code.

try 
{ }
catch
{ }
finally
{ }


41) Can you have a Try block with no Catch block or Finally block ?

No. A Try block must be followed by either a Catch block, a Finally block or both.

try 
{ }


42) Can multiple Catch blocks be executed ?

No. When an exception occurs the correct catch block is executed and then control is passed to the finally block.


43) What happens if the exception is not matched by a Catch block ?

The exception will be treated as unhandled and will propogate up the call stack.


44) When does the Finally block get executed ?

It always gets executed even if an exception occurs.


45) Can you put a return statement inside a Finally block ?

No.


46) What would the syntax be to catch any possible type of Exception ?

Catch 
Catch (System.Exception)
Catch (System.Exception ex)


47) Can you define your own User Defined Exceptions ?

Yes. You can derive from the System.Exception class.
Never use the System.ApplicationException class.

class UserNameInvalidException : System.Exception 
{
   class UserNameInvalidException(string MyMessage) : base (MyMessage)
   {
   }
}


48) Is there any difference between the following lines of code ?

try 
{ }
catch (System.Exception ex)
{
   throw;
   throw ex;
   throw new System.Exception("message",ex);
}

throw - will rethrow the original exception and preserve the stack trace.
throw ex - will rethrow the original exception but resets the stack trace.
throw new System.Exception - will create a brand new exception which resets the stack trace and loses the type of exception.


49) Can you give some examples of different types of Exceptions ?

ArgumentNullException - An argument that is passed to a method has a null value.
IndexOutOfRangeException - An index is outside the bounds of an array or collection.
StackOverflowException - An arithmetic, casting or conversion operation results in an overflow.
DivideByZeroException - The denominator in an Integer or Decimal division is zero.


50) What is Object Orientated programming ?

This is a style of programming that is based on objects containing methods and properties arranged in a hierarchy.
This type of programming is based around four key features:
Polymorphism - Create routines that can operate on objects of different types. This is handled by late binding and multiple interfaces.
Encapsulation - Hide parts of the implementation and hide complexity. This is achieved using access modifiers.
Inheritance (Interface) - (Public Inheritance) Define methods (without implementation) that must be declared in a derived class.
Inheritance (Implementation) - (Private Inheritance) Inherit method implementation from a base class.


51) Is C# an Object Orientated programming language ?

Yes. It has the four key features.


52) Can you describe the four different types of inheritance ?

Single Inheritance - contains one base class and one derived class.
Hierarchical Inheritance - contains one base class and multiple derived classes with the same base class.
Multi-level Inheritance - contains a class derived from another derived class.
Multiple Inheritance - contains a class derived from multiple base classes.


53) How would you describe the default Access Modifier ?

The default access modifier is the least restrictive based on the current scope.


54) Can you describe the five different levels of accessibility ?

public - everywhere
protected internal - inside the class, from any derived class in any assembly and from anywhere in that assembly (base classes)
internal - anywhere in that assembly
protected - inside the class and from any derived class in any assembly (base classes)
private - inside the class


55) What is a Structure ?

A structure is a value type that is 'sealed' by definition and cannot be inherited from.
A structure can contain fields, methods, properties, enumerations, delegates, events, constructors, indexers.
A structure cannot contain finalizers.
The default access modifier for a structure is 'internal'.
The default access modifier for a Structure member is 'private' ??
This inherits from System.ValueType which inherits from object.

internal struct MyStructure 
{
   public string _TextField;
   internal void MyMethod();
   private string Property_Name { get; set: }
}


56) Can a Structure contain implementation ?



57) What type of Access Modifiers can you have on Structure members ?

Structure members can be 'public', 'internal' or 'private'.
Structure members cannot be 'protected internal' or 'protected' because they do not support inheritance.


58) What is the difference between a Structure and a Class ?

All structures are value types where as classes are reference types.
You cannot have 'protected' or 'protected internal' access modifiers in a structure because structures do not support inheritance.
Structures cannot have destructors but classes can.


59) What are the similarities between a Structure and a Class ?

Both can contain fields, methods, properties.
Both can inherit from interfaces.
You can have 'public', 'private' and 'internal' access modifiers.


60) Can a Structure inherit from an Interface ?

Yes. You can inherit from one or more interfaces.
A structure cannot inherit from a Structure or Class.
A class cannot inherit from a Structure.
An interface cannot inherit from a Structure.

struct Structure : MyInterface, MyInterface2 
{ }


61) Describe the difference between passing a Structure to a method and passing a Class to a method ?

When a structure is passed by value "a copy" of the object is passed in.
When a class is passed by value the actual object is passed in.
When a structure is passed by reference the actual object is passed in.


62) Can a Structure have a Constructor ?



63) What is an Interface ?

An interface is a contract that defines the signature for any object that is derived from it.
An interface can contain methods, properties, indexers and events.
An interface cannot contain constants, fields, instance constructors, types or static members.
The default access modifer for an interface is 'internal'.
Interfaces can be public, private, internal.

internal interface MyInterface 
{
   void MyMethod(string MyText);
   string Property_Name { get; set; }
}


64) Can an Interface contain implementation ?



65) What type of Access Modifiers can you have on Interface members ?

None. You cannot use any explicit access modifiers.
Interface members are always 'public' by definition.


66) Can an Interface inherit from an Interface ?

Yes. An interface can only inherit from one or more interfaces.
An interface cannot inherit from a Structure or Class.

interface MyInterface2 : MyInterface 
{ }


67) What is a Class ?

A class is the definition of an object.
A class can contain fields, methods, properties, constructors, finalizer, destructor, indexers.
A class is a reference type.
The default access modifier for a class is internal.

internal class MyClass 
{ }


68) What type of Access Modifiers can you have on Class members.

Class members can be 'public', 'protected internal', 'internal', 'protected', 'private'.


69) Can a Class inherit from a Interface ?

Yes. You can inherit from one or more interfaces.

class MyClass : MyInterface, MyInterface2, MyInterface3 
{ }

There must be Explicit Interface Implementation when you have two interfaces with the same methods.


70) Can a Class inherit from a Class ?

Yes. However you cannot inherit from multiple classes.

class MyDerived : MyClass 
{ }


71) Can a Class inherit from a Class and an Interface ?

Yes. The class must come first and the interface second ??

class MyDerived : MyClass, MyInterface 
{ }


72) If you have an Internal Class should you make the members 'internal' or 'public' ?

A public member of an internal class is effectively internal because the class only has internal scope.
The members should be declared 'public' in case you want to change the class later to be public instead of internal.


73) Can you describe a situation when you need to have a 'public' method inside an Internal Class ?

Yes. This is necessary when an internal class implements an internal interface.
Interface members are always 'public' by definition and therefore the class must implement that member using a public access modifier.

internal interface MyInterface 
{
   void MyMethod()
}
internal class MyClass : MyInterface
{
   public void MyMethod()
   { }
}


74) What is a Nested Class ?

A nested class is a class declaration that occurs inside another class.
The default access modifier for a nested class is 'private'.

class MyClass 
{
   class MyNested
   { }
}


75) What is a Class Method ?

A class method is a procedure or function that contains statements.

class MyClass 
{
   public void MyMethod()
   int MyMethod2()
}


76) What is the difference between 'ref' and 'out' parameters ?

An argument passed as ref must be initialised before passing into the method.
An argument passed as out does not need to be initialised beforehand.

public void MyMethod(ref string myText1, 
                     out string myText2)
{
}


77) Can you describe Method Overloading ?

This is when you create another method with the same name but with a different signature.
The compiler determines which method to invoke at run-time.
There are three ways a method can be overloaded:
*) By changing the number of parameters.
*) By changing the order of the parameters.
*) By changing the data types of the parameters.


78) What is a Class Property ?

A property provides a way of exposing an internal data element inside a class.
You create a property by providing set and get property accessors.
The get accessor is used to return a value.
The set accessor is used to assign a new value.

class MyClass 
{
   private string _TextField;

   public string Property_Name
   {
      get { return _TextField; }
      set { _TextField = value; }
   }
}


79) What is an Auto Implemented Property ?

This provides a shorthand for the above by implicitly creating a private field.

public string Property_Name { get; set; } 


80) What does the 'abstract' modifier do ?

This can only be applied to methods and classes.
When applied to a method it creates an abstract method that HAS NO implementation.
An abstract method can only appear in an abstract class.


81) What is an Abstract Class ?

This class cannot be instantiated and can only be used as a base class.
Abstract classes can only be 'public'
You must provide at least one abstract method in an abstract class.
They can provide implementation.
Abstract class members can be 'public', 'protected internal', 'internal','protected','private'.
An abstract method is by definition also a virtual method.

public abstract class MyAbstract 
{
   public abstract void MyMethod()
   internal abstract void MyMethod2()
   protected abstract void MyMethod3()
}


82) What is the difference between an Abstract Class and an Interface ?

An abstract class can have private and protected methods but an interface can only have public.
An interface only defines the methods (or signature) but an abstract class can provide code behind these methods.
Classes can implement multiple interfaces but can only implement one abstract class.
Any class can extend an abstract class. Only an interface can extend another interface.
Methods in an abstract class can be abstract or concrete. Methods in an interface are all abstract.
An abstract class can have a constructor. An interface cannot have a constructor.
A class extending an abstract class may or may not implement any of its methods. All methods of an interface have to be implemented when a class implements that interface.


83) Can you describe a situation when you need to have an 'internal' method inside an abstract class ?

If you want to prevent external inheritance while retaining visibility.


84) What is the difference between a Base Class and a Derived Class ?

A base class is a class declaration that is used as a basis for a second derived class.
If you want to extend the functionality or customise the functionality of an existing class you can derive another class from it.
A derived class inherits both structure and behaviour.


85) What does the 'static' modifier do ?

This can be applied to classes and methods.
It means you can call this method without instantiating the object.
A static class can only contain static members.
You cannot have a virtual static member.

static class MyClass 
{
   static void MyMethod()
}


86) Can a Class inherit from a Static Class ?

No.


87) What does the 'virtual' modifier do ?

This is applied to methods.
It means you HAVE THE OPTION TO override this method in a derived class.
You cannot have a private virtual method.

class MyClass 
{
   public virtual void MyMethod()
   {
      MessageBox.Show("MyClass - MyMethod");
   }
}


88) What does the 'override' modifier do ?

It means you have REPLACED the method in the derived class.
This changes the behaviour of the derived class.
You can override virtual methods in a normal class.
You can override abstract methods in an abstract class.
The method signature must be identical.

class MyClass 
{
   virtual void MyMethod()
   { MessageBox.Show("MyClass - MyMethod"); }
}

class MyDerived : MyClass
{
   override void MyMethod()
   { MessageBox.Show("MyDerived - MyMethod"); }
}

or

abstract class MyAbstractClass 
{
   abstract void MyMethod()
   { MessageBox.Show("MyAbstractClass - MyMethod"); }
}

class MyDerived : MyAbstractClass
{
   override void MyMethod()
   { MessageBox.Show("MyDerived - MyMethod"); }
}


89) What is displayed when you run the following code ?

MyClass a = new MyDerived(); 
MyDerived b = new MyDerived();
a.MyMethod();
b.MyMethod();

Both methods return MyDerived because this method has been overridden.
MyDerived - MyMethod
MyDerived - MyMethod


90) What does the 'new' modifier do ?

This can only be applied to methods.
It means you have CREATED a method with the same name in a derived class.
Not used very often.
This is the DEFAULT when your derived class has members with the same name as the base class.

class MyClass 
{
   virtual void MyMethod()
   { MessageBox.Show("MyClass - MyMethod"); }
}
class MyDerived : MyAbstract
{
   new void MyMethod()
   { MessageBox.Show("MyDerived - MyMethod"); }
}


91) What is displayed when this code runs ?

MyClass a = new MyDerived(); 
MyDerived b = new MyDerived();
a.MyMethod(); // MyClass - MyMethod
b.MyMethod(); // MyDerived - MyMethod


92) What is the difference between the 'new' modifier and the 'override' modifier ?

The 'override' modifier will create a different method in the derived class.
The 'new' modifier will replace the base class member.


93) What does the 'sealed' modifier do ?

This is applied to classes and methods.
It means you cannot override the base class method.
A sealed class cannot be inherited from.
A sealed method cannot be overridden in a derived class.

class MyClass 
{
   sealed void MyMethod()
}


94) What does the 'volatile' modifier do ?

It means that its value can be changed by another thread.
This modifier tells the compiler that this field could be accessed on multiple threads.
When the code is compiled, the compiler will make various optimisations on the assumption that variables will only be accessed by one thread at a time.
Using this modifier ensures that one thread retrieves the most up-to-date value written by another thread.
Writing non-blocking or lock free multithreaded code is very complicated.

class MyClass 
{
   volatile void MyMethod()
}


95) What does the 'readonly' modifier do and how is different to 'const' ?

This is a modifier that can be used on fields.
Therefore readonly fields can have different values depending on the constructor used.

class MyClass 
{
   public readonly int _NumberField = 5;
}


96) What is the difference between the 'readonly' modifier and the 'const' modifier ?

A 'readonly' variable can be initialised at run-time or in the class's constructor.
A 'constant' variable must be initialised at compile-time in the declaration.


97) What is a Constructor ?

A constructor is a member function in a class that has the same name as the class.
This method is automatically invoked when an object is created.
It can be used to initialise the class members.
They can be overloaded.
They do not return a value.
Having a class constructor is optional.

class MyClass 
{
   void MyClass() // constructor
   {
   }
}


98) Can you overload the default Constructor ?

Yes. You can leave the parameterless one as well if you want to.

class MyClass 
{
   void MyClass(string myText) // constructor
   {
   }
}


99) Can you describe when you would use a Private Constructor ?

Private constructors are used to prevent creating instances of a class that have no instance fields or methods.
It ensures the object can only be created by a member of the class.

class MyClass 
{
   private MyClass() // constructor
   {
   }
}


100) Can a Class have a Static Constructor ?

Yes. A non static class can have a static constructor. It can be used to initialize static data.
It is called automatically before any static members are referenced.
It is called automatically before the first instance is created.

class MyClass 
{
   static MyClass() // constructor
   {
   }
}


101) What is the 'base' keyword used for ?

The base keyword is used to access members of the base class from within a derived class.
The base class can only be accessed in a constructor, an instance method or an instance property accessor.
If the derived class overrides a base class method then the base keyword can be used to call the base class method.
You can also use the base keyword to specify which base class constructor should be called on the derived class constructor.


102) Is it possible for a class to inherit the constructor of its base class ?

No.


103) If a base class has an overloaded constructor and a derived class also has an overloaded constructor how can you call the base class constructor ?

public class MyClass 
{
   public MyClass(string MyText) //constructor
   {
   }
}
public class MyDerived : MyClass
{
   public MyDerived(string MyText, int myValue) : base(MyText)
   {
   }
}


104) What is a Destructor ?

A destructor implicitly calls the System.Object.Finalize method on the base class of the object.
A destructor cannot be called, it is invoked automatically.

public class MyClass 
{
   ~MyClass()
   {}
}

This is equivalent to the following:

public class MyClass 
{
   protected override void Finalize()
   {
      base.Finalize();
   }
}


105) What is a Finalizer ?

The word Finalizer refers to the System.Object.Finalize method.
Managed memory which is allocated using the new operator does not need to be explicitly released because it is released by the garbage collection process automatically.
This method can be used to clean up and destroy any unmanaged memory resources.
However there are two shortcomings with this method:
*) This method (if it runs at all) is called at some undetermined time in the future which means the resource is not cleaned up immediately.
*) This method executes on a different thread and therefore the memory is not actually released until the automatic garbage collection runs again.


106) Can you describe the Dispose Pattern ?

This pattern provides a standard convention for working around the shortcomings of the Finalize method.
This pattern uses the System.IDisposable interface.

public class MyObject : System.IDisposable 
{
   bool _disposed;

   public void Dispose()
   {
      Dispose(true);
      GC.SuppressFinalize(this);
   }

   protected virtual void Dispose(bool disposeOfManaged)
   {
      if (this._disposed == false)
      {
         if (disposeOfManaged == true)
         {
            //code to clean up managed resources
            component.Dispose();
         }

         //code to clean up unmanaged resources

         this._disposed = true;
      }
   }

   protected override void Finalize()
   {
      Dispose(false);
   }
}


107) Can you describe how Garbage Collection works ?

The garbage collector automatically gets information about unreferenced objects from the .NET runtime environment and then invokes their Finalize method.

GC.Collect 


108) What is a Delegate ?

A delegate defines the signature for a particular method.
Delegates give you a way of calling a method at run-time.
A delegate can only hold the reference to methods that have the same signature.
Examples include: type safe functions, pointers, callbacks.


109) What is a Multicast Delegate ?

A Delegate object holds a reference to a single method.
It is possible for a delegate object to hold references to multiple methods.
These delegates are called multicast or combinable delegates.


110) What is a Generic Delegate ?

There are three types: Func, Action, Predicate.


111) What is the difference between a Delegate and an Event ?

An event is something that can be added or removed from an object.
When you add or create an event you are storing a delegate reference which can then be called at run-time.


112) What is an Event ?

An event is an indication that a state is about to change or that a state has changed.
Events are declared using delegates.


113) Can you describe some situations when you would use Delegates ?

Callback Mechanism -
Asynchronous Processing -
Multi-Casting -
Abstract and Encapsulate Methods -


114) What is a HashTable ?

A hash table is a data structure that implements the IDictionary interface.
Is an example of a collection.
It is used to store multiple items and each one is associated with a unique key.
A hash table is an object that holds key-value pairs.


115) What is Serialisation ?

Converting an object into a stream of bytes is called serialisation.
This is useful when we want to transport, save or pass an object around.
For an object to be serialized it needs to inherit the ISerialize interface.
De-serialization is the reverse process of creating an object from a stream of bytes.


116) What do the [Serializable] and [NonSerializable] attributes do ?

System.SerializableAttribute 
System.NonSerializableAttribute

[Serializable()]
public class MyClass

This can be applied to classes and methods.
Used to indicate that a class or method can be serialized.


117) What is Multi-Threading ?

This allows different tasks to be carried out in parallel.
The advantage of a divide and conquer strategy is that it will improve performance.


118) What is the difference between a Background Thread and a Foreground Thread ?

A foreground thread runs indefinitely.
A background thread terminates when the foreground thread is stopped.


119) What does the 'async' keyword do ?

Introduced in .NET 4.5.


120) What is displayed when you run the following code ?

public main() 
{
   Method1()
   MessageBox.Show("Two");
}

public async void Method1()
{
   thread.wait(10);
   MessageBox.Show("One");
}

The Method1 is executed on a different thread and this message box will only be displayed after the 10 seconds.
"Two"
"One"


121) What does the [ThreadStatic] attribute do ?

System.ThreadStaticAttribute 

This is used to indicate a variable is thread safe.
A static variable is not shared between threads.
Each executing thread will have a separate instance of the field and will independently set and get values for that variables.
If the variable is accessed on a different thread, it will contain a different value.


122) What is Reflection ?

This is a technique that allows you to fetch type (assembly) information at runtime programmatically. You can also achieve late binding using Reflection.
This allows you to examine or modify the meta data from assemblies at runtime.
This is useful for:
Viewing metadata -
Type discovery - examine the types in other assemblies
Late binding - based on Type discovery
Creating new types at runtime (Reflection Emit) Creating custom classes at runtime which will run significantly faster than a more generic class created at compile time


Reflection can be used to adapt a program execution at run-time
This is the process by which a program can read its own meta-data
A program is said to reflect on itself extracting metadata from its assembly and using that metadata to either inform the user or modify its behaviour


123) If you pass an object into a method and you want to find out what type it is - how can you do this ?

Declare the members you need in a class or interface and cast to that using Reflection.

public static T Cast<T>(object obj) 
{
   return (T)obj;
}

This method can then be invoked using Reflection.

methodInfo castMethod = this.GetType().GetMethod("Cast").MakeGenericMethod(t) : 
object castedobject = castmethod.Invoke(null, new object[] {obj});


124) What is ADO.NET ?

This provides a consistent way to access different types of data sources and different types of databases.


125) Can you describe the DataReader class in ADO.NET ?

The DataReader is a forward only approach to getting read-only data.
This will retain an open connection to the database while retrieving data.


126) Can you describe a DataSet in ADO.NET ?

The DataSet is a disconnected cache of data that allows you to create multiple tables and fill them with data from different sources.
A DataSet object is more inline with a VBA ADO recordset.
A DataSet can be used with no database and could be populated with data from an XML file or other source.
It also allows you to enforce relationships between the tables.
DataSets can be either Typed or UnTyped.
DataSets can be serialized.


127) What is the difference between the 'System.Data.SQLClient' namespace and the 'System.Data.OleDbClient' namespace ?

OleDbClient - This is a general data provider for targetting any OLE DB data source, including Access.
SQLClient - This is a specific data provider for targetting SQL Server databases.


128) Write the pseudo code to extract data from an Access database ?



129) What is the 'using' statement ?

The using block is used to obtain a resource and use it and then automatically dispose of it at the end of the block.
This allows you to not specify the data type at declaration ?


130) Can you describe the concept of Generics ?

Generics provide type-safety to your class at compile-time


131) What do SOAP and REST stand for ?

SOAP = Simple Object Access Protocol
REST = REpresentational State Transfer


132) What are the differences between SOAP and REST ?

SOAP - describes itself using a wsdl (web description language) and has a defined contract
REST - lightweight http protocol that can return different formats (text, html, xml)


133) How can you return an error from a SOAP Web Service ?

Make sure the exception raised is derived from the SOAPException class.


134) Write a function that takes a date and returns the quarter that the date is in ?

public static int GetQuarter(System.DateTime myDateTime) 
{
   return System.Convert.ToInt32(System.Math.Ceiling(myDateTime.Month(3D));
}

The "D" literal number suffix tells the compiler that the literal value passed to the Month method is of data type double.
You can use this when you want an integer number to be treated as a double.


135) LINQ Question

.FirstOrDefault 


136) What is the pre-requisite for connection pooling ?



137) Write code that will resize a System.Drawing.Rectangle by reducing its height and width by 5 points ?

System.Drawing.Rectangle myRectangle = new System.Drawing.Rectangle(100,100); 
myRectangle.Inflate(-5,-5);


138) What is well formed XML ?

XML containing descriptive markup tags where all the tags are correctly formed and follow certain rules
Must contain at least one element
Must contain a unique opening and closing tag
All tags must be nested correctly
Xml tags are case sensitive
Attribute values must always be enclosed in double quotes.


139) What is XSLT ?

This stands for XML Stylesheet Language Transformations and is an xml based document used for transforming one type of XML into another type of XML.


140) What is RIXML ?

Research Information Exchange Markup Language
It is an XML standard that provides a set of tags that can be used to describe investment research documents.


141) What is a COM add-in ?

This Is a type of add-in that can be used to provide additional application-level functionality
A COM add-in implements the IDTExtensibility2 interface
It has been possible to create these since Visual Studio 2002.


142) What is a VSTO add-in ?

This is a type of add-in that can be used to provide additional application-level functionality
A VSTO add-in implements the IStartup interface (which is implemented in the Addins class/interface)
This interface is strongly typed and does not rely on late binding.
It has only been possible to create these since Visual Studio 2005.


143) What is ClickOne ?

ClickOnce is a deployment technology that allows you to create self-updating Windows-based applications that can be installed and run with minimal user interaction.
The core ClickOnce deployment architecture is based on two XML manifest files: a deployment manifest and an application manifest.


144) What is a Deployment Manifest ?

This is a file with the extension (.deploy) but in the context of VSTO this extension is (.vsto).
They are standard clickonce manifests but have a different file extension to enable the VSTO runtime to handle the file).
This file identifies which version of the application is currently deployed and also contains other useful deployment information.
There is only one deployment manifest per customisation and it references the application manifest.


145) What is an Application Manifest ?

This is a file with the extension (.manifest).
This file describes all the assemblies, dependencies, permissions etc.
And there is one file for each version of the customisation.


146) Can you describe Ribbon Customisation ?

Allows you to add (or replace) functionality to existing tabs, create new tabs, groups and commands
This can be done in two ways:
*) Using the CustomUI Editor to embed XML markup into the open xml format.
*) Using Visual Studio using to create a VSTO or COM add-in.


147) What is an Assembly ?

In .NET an assembly is a partially compiled code library used in deployment.
There are two types: process assemblies (exe) and library asemblies (dll).


148) What is an Application Domain ?

An application domain provides a flexible and secure method of isolating running .NET applications.
Before a .NET assembly can be executed it must be loaded into an application domain.
Errors in one application domain cannot affect code running in any other application domains.


149) What is a Namespace ?

A namespace provides a way of organising and grouping your classes.


150) What is Unit Testing ?



151) Can you give some examples of different types of test cases ?

Positive test cases - correct data, correct output
Negatve test cases - incorrect / missing / invalid data, proper handling
Exception test cases - exceptions are thrown and handled properly



© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

Prev