1. Home
  2. Docs
  3. C#
  4. Interview Questions
  5. C# Technical Test Revision Guide

C# Technical Test Revision Guide

Below is a comprehensive C# technical test revision guide with explanations and code snippets covering:

  • Basic syntax & structure
  • Variables & data types
  • Control flow (if, switch)
  • Loops (for, while, do-while, foreach)
  • Methods
  • Arrays & collections
  • Strings
  • Object-Oriented Programming (OOP)
  • LINQ
  • Exception handling
  • File I/O
  • Asynchronous programming
  • Delegates, events & lambda expressions
  • Generics
  • Basic data structures
  • Algorithm-style logic questions

You can use this as a revision reference and practice rewriting these examples from memory.


1. Basic Program Structure

A simple C# console application:

using System;

namespace InterviewPrep
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
        }
    }
}

Key points:

  • using imports namespaces.
  • namespace groups related classes.
  • class defines a type.
  • Main is the entry point.

2. Variables and Data Types

Primitive Types

int number = 10;
double price = 19.99;
float temperature = 36.6f;
decimal salary = 25000.50m;
bool isActive = true;
char grade = 'A';
string name = "David";

Implicit Typing with var

var age = 30;        // inferred as int
var message = "Hi";  // inferred as string

Constants

const double Pi = 3.14159;

3. Conditional Statements

If / Else

int number = 15;

if (number > 10)
{
    Console.WriteLine("Greater than 10");
}
else if (number == 10)
{
    Console.WriteLine("Equal to 10");
}
else
{
    Console.WriteLine("Less than 10");
}

Ternary Operator

int age = 18;
string result = age >= 18 ? "Adult" : "Minor";

Switch Statement

int day = 3;

switch (day)
{
    case 1:
        Console.WriteLine("Monday");
        break;
    case 2:
        Console.WriteLine("Tuesday");
        break;
    case 3:
        Console.WriteLine("Wednesday");
        break;
    default:
        Console.WriteLine("Invalid day");
        break;
}

Modern switch expression:

string dayName = day switch
{
    1 => "Monday",
    2 => "Tuesday",
    3 => "Wednesday",
    _ => "Unknown"
};

4. Loops

For Loop

for (int i = 0; i < 5; i++)
{
    Console.WriteLine($"Iteration {i}");
}

Common interview task: Sum numbers 1–100

int sum = 0;

for (int i = 1; i <= 100; i++)
{
    sum += i;
}

Console.WriteLine(sum);

While Loop

int count = 0;

while (count < 5)
{
    Console.WriteLine(count);
    count++;
}

Do-While Loop

int number;

do
{
    Console.WriteLine("Enter a number greater than 10:");
    number = int.Parse(Console.ReadLine());
}
while (number <= 10);

Foreach Loop

int[] numbers = { 1, 2, 3, 4 };

foreach (int num in numbers)
{
    Console.WriteLine(num);
}

5. Methods

Basic Method

static int Add(int a, int b)
{
    return a + b;
}

Usage:

int result = Add(5, 3);

Method Overloading

static int Multiply(int a, int b)
{
    return a * b;
}

static double Multiply(double a, double b)
{
    return a * b;
}

Optional Parameters

static void Greet(string name, string greeting = "Hello")
{
    Console.WriteLine($"{greeting}, {name}");
}

6. Arrays

Declaring Arrays

int[] numbers = new int[5];
int[] values = { 1, 2, 3, 4 };

Loop Through Array

for (int i = 0; i < values.Length; i++)
{
    Console.WriteLine(values[i]);
}

Find Maximum in Array

int[] numbers = { 3, 7, 2, 9, 5 };
int max = numbers[0];

foreach (int num in numbers)
{
    if (num > max)
    {
        max = num;
    }
}

Console.WriteLine($"Max: {max}");

7. Lists and Collections

List<T>

using System.Collections.Generic;

List<string> names = new List<string>();
names.Add("Alice");
names.Add("Bob");
names.Remove("Alice");

foreach (var name in names)
{
    Console.WriteLine(name);
}

Dictionary<TKey, TValue>

Dictionary<string, int> ages = new Dictionary<string, int>();
ages["Alice"] = 25;
ages["Bob"] = 30;

Console.WriteLine(ages["Alice"]);

Check if key exists:

if (ages.ContainsKey("Alice"))
{
    Console.WriteLine("Exists");
}

8. Strings

String Operations

string text = "Hello World";

Console.WriteLine(text.Length);
Console.WriteLine(text.ToUpper());
Console.WriteLine(text.Substring(0, 5));
Console.WriteLine(text.Contains("World"))

Reverse a String (Interview Classic)

string input = "hello";
char[] chars = input.ToCharArray();
Array.Reverse(chars);
string reversed = new string(chars);

Console.WriteLine(reversed);

Manual reverse:

string Reverse(string input)
{
    string result = "";

    for (int i = input.Length - 1; i >= 0; i--)
    {
        result += input[i];
    }

    return result;
}

9. Object-Oriented Programming (OOP)

Class and Object

class Person
{
    public string Name { get; set; }
    public int Age { get; set; }

    public void Introduce()
    {
        Console.WriteLine($"Hi, I'm {Name} and I'm {Age} years old.");
    }
}

Usage:

Person p = new Person();
p.Name = "John";
p.Age = 28;
p.Introduce();

Constructor

class Car
{
    public string Model { get; set; }

    public Car(string model)
    {
        Model = model;
    }
}

Inheritance

class Animal
{
    public void Speak()
    {
        Console.WriteLine("Animal sound");
    }
}

class Dog : Animal
{
    public void Bark()
    {
        Console.WriteLine("Woof");
    }
}

Polymorphism (Override)

class Shape
{
    public virtual double GetArea()
    {
        return 0;
    }
}

class Circle : Shape
{
    public double Radius { get; set; }

    public override double GetArea()
    {
        return Math.PI * Radius * Radius;
    }
}

Interface

interface ILogger
{
    void Log(string message);
}

class ConsoleLogger : ILogger
{
    public void Log(string message)
    {
        Console.WriteLine(message);
    }
}

10. Exception Handling

try
{
    int x = int.Parse("abc");
}
catch (FormatException ex)
{
    Console.WriteLine("Invalid format");
}
finally
{
    Console.WriteLine("Done");
}

11. LINQ

using System.Linq;

List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };

var evenNumbers = numbers.Where(n => n % 2 == 0);

foreach (var num in evenNumbers)
{
    Console.WriteLine(num);
}

Select:

var squared = numbers.Select(n => n * n);

OrderBy:

var sorted = numbers.OrderByDescending(n => n);

12. Delegates and Lambda Expressions

Delegate

delegate int Operation(int a, int b);

static int Add(int x, int y) => x + y;

Operation op = Add;
Console.WriteLine(op(5, 3));

Lambda Expression

Func<int, int, int> multiply = (a, b) => a * b;
Console.WriteLine(multiply(4, 5));

13. Asynchronous Programming

using System.Threading.Tasks;

static async Task<int> GetNumberAsync()
{
    await Task.Delay(1000);
    return 42;
}

static async Task Main()
{
    int result = await GetNumberAsync();
    Console.WriteLine(result);
}

14. File Handling

Write to file:

using System.IO;

File.WriteAllText("test.txt", "Hello file");

Read file:

string content = File.ReadAllText("test.txt");
Console.WriteLine(content);

15. Common Algorithm Questions

Check if Number is Prime

bool IsPrime(int number)
{
    if (number <= 1)
        return false;

    for (int i = 2; i <= Math.Sqrt(number); i++)
    {
        if (number % i == 0)
            return false;
    }

    return true;
}

Fibonacci Series

void Fibonacci(int n)
{
    int a = 0, b = 1;

    for (int i = 0; i < n; i++)
    {
        Console.WriteLine(a);
        int temp = a;
        a = b;
        b = temp + b;
    }
}

Factorial (Recursive)

int Factorial(int n)
{
    if (n <= 1)
        return 1;

    return n * Factorial(n - 1);
}

16. Sorting Example (Bubble Sort)

void BubbleSort(int[] array)
{
    for (int i = 0; i < array.Length - 1; i++)
    {
        for (int j = 0; j < array.Length - i - 1; j++)
        {
            if (array[j] > array[j + 1])
            {
                int temp = array[j];
                array[j] = array[j + 1];
                array[j + 1] = temp;
            }
        }
    }
}

17. Basic Dependency Injection Pattern

class OrderService
{
    private readonly ILogger _logger;

    public OrderService(ILogger logger)
    {
        _logger = logger;
    }

    public void ProcessOrder()
    {
        _logger.Log("Processing order...");
    }
}

Usage:

ILogger logger = new ConsoleLogger();
OrderService service = new OrderService(logger);
service.ProcessOrder();

18. Nullable Types

int? number = null;

if (number.HasValue)
{
    Console.WriteLine(number.Value);
}

Null-coalescing operator:

int result = number ?? 0;

19. Basic Unit-Testable Logic Example

class Calculator
{
    public int Add(int a, int b)
    {
        return a + b;
    }
}

20. Practice Scenarios

You should practice:

  • Reverse a string without built-in methods
  • Find duplicates in array
  • Count vowels in string
  • Check palindrome
  • Implement stack using List
  • Parse CSV line into object
  • Filter list of objects by property
  • Use LINQ to group by property
  • Write async method that calls another async method

Final Interview Advice (Technical Tests)

Given your background in development and structured systems:

  1. Write clean, readable code.
  2. Use meaningful variable names.
  3. Handle edge cases.
  4. Don’t overcomplicate simple logic.
  5. Explain your thinking if it’s a live test.

How can we help?