User FAQs

If you have a question, please send it to us.

1) Is C# a Compiled or Interpreted programming language ?
C# is Compiled which means there is a build/compile step. VBA is also compiled.

2) Is C# a Strongly or Loosely Typed programming language ?
C# is Strongly Typed because every variable and constant must be defined with a specific data type.
Strongly typed languages imposes a rigorous set of rules and therefore guarantees a certain consistency of results.
Strongly typed languages are slower to compile but faster to run.
Strongly typed languages can be statically typed (VBA without Variant and with Option Explicit) or dynamically typed (Python).

string myText; 

3) Is C# a Statically or Dynamically Typed programming language ?
C# is Statically Typed because data types cannot change at run-time.
Statically typed languages have their data types checked at compile time.
In .NET 4.0 it is possible to use the "dynamic" keyword which allows you to turn off compile time type checking.

4) Is C# an Object Orientated or Functional programming language ?
C# is Object Orientated, although it does support some functional programming techniques.
Polymorphism - Yes. Create routines that can operate on objects of different types. This is handled by late binding and multiple interfaces.
Encapsulation - Yes. Hide parts of the implementation and hide complexity. This is achieved using access modifiers.
Inheritance (Interface) - Yes. (Public Inheritance) Define methods (without implementation) that must be declared in a derived class.
Inheritance (Implementation) - Yes. (Private Inheritance) Inherit method implementation from a base class.
Abstraction -

5) What is the difference between Procedural and Object Oriented programming ?
Procedural is based on 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.
Object Oriented is based on classes which have methods and properties. Objects are then created from these classes.
Access modifiers can be used to hide implementation.
Inheritance can be used to create reusable components.

6) 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 data type.
The default access modifier for an enumeration is public.

public enum enCities 
    london = 1,
    tokyo = 2

7) Is it possible to associate a text string with each Enumeration value ?
Yes. You can amend the Description component to each value.

public enum enCities 
    london = 1,
    tokyo = 2

8) Is it possible to return the int value from an Enumeration ?
Yes. You can just cast it to an int.

int myValue = (int); 

9) Is it possible to return the enumeration from a corresponding text string ?
Yes. You can use the enumeration Parse method.

string myCityName = "london"; 
enCities myEnum = (enCities)System.Enum.Parse(typeof(enCities), myCityName);

10) Is it possible to return the string name instead of the number from an Enumeration ?
Yes. You can use the enumeration GetName method.

int myValue =; 
string myCityName = System.Enum.GetName(typeof(enCities), myValue);

11) Is it possible to iterate through the values defined in an Enumeration ?
Yes. Although the Enum base class does not support the IEnumerable interface.
You can however use the GetValues method which returns all the enumerated values in an array.

foreach (enCities cityenum in System.Enum.GetValues(typeof(enCities))) 
    System.Console.WriteLine( cityenum + " (" + (int)cityenum + ")" );

12) Is it possible to iterate through the names defined in an Enumeration ?

foreach (string cityname in System.Enum.GetNames(typeof(enCities))) 
    System.Console.WriteLine( cityname + " (" + (int)System.Enum.Parse(typeof(enCities), cityname) + ")" );

13) Write code to iterate through the values defined in an Enumeration ?
First create an Extension Method that can easily return the Description.
This extension method will use reflection to get an array of the enum's members, and then from the array's first element's member info it will check and return if the member has a Description attribute defined.
If that attribute exists, then it will return the Description value, this will be contained within the GenericEnum variable's ToString() method.

public static class EnumExtensionMethods 
    public static string GetDescription(this Enum GenericEnum)
        Type genericEnumType = GenericEnum.GetType();
        MemberInfo[] memberInfo = genericEnumType.GetMember(GenericEnum.ToString());
        if ((memberInfo != null && memberInfo.Length > 0))
            var _Attribs = memberInfo[0].GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
            if ((_Attribs != null && _Attribs.Count() > 0))
                return ((System.ComponentModel.DescriptionAttribute)_Attribs.ElementAt(0)).Description;
        return GenericEnum.ToString();

foreach (enCities city in System.Enum.GetValue(typeof(enCities)))
    string enumName = System.Enum.GetName(typeof(enCities), myValue);
    string enumDescription = city.GetDescription();
    System.Console.WriteLine( {0} - ( {1} ), enumName, enumDescription);

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

for (int mynumber = 0; mynumber < MyList.Length; mynumber++)

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

foreach (int mynumber in MyList)

16) What is the difference between 'break' and 'continue' inside a for loop ?
break - breaks out of the loop completely.
continue - continues to execute the next iteration.

for (int i = 0; i < 10; i++) 
    if (i == 0)
        continue; // the for-loop will jump to the next loop
    if (i == 5)
        break; // the for-loop with exit

17) Write a Switch statement to match against two conditions ?

switch (myNumber) 
   case < 10:
   case >= 10:

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext