C# interview questions

Want to become an expert in cracking C# interview questions?

Start with practicing the questions below. Whether a question involves multiple choice or live coding, we will give you hints as you go and tell you if your answers are correct or incorrect.

After that, take our timed public C# interview questions test.

To use our service for testing developers, purchase one of the paid plans for companies.


1. TwoSum
C# Algorithmic thinking Searching Public

Write a function that, given a list and a target sum, returns zero-based indices of any two distinct elements whose sum is equal to the target sum. If there are no such elements, the function should return null.

For example, FindTwoSum(new List<int>() { 1, 3, 5, 7, 9 }, 12) should return any of the following tuples of indices:

  • 1, 4 (3 + 9 = 12)
  • 2, 3 (5 + 7 = 12)
  • 3, 2 (7 + 5 = 12)
  • 4, 1 (9 + 3 = 12)
Easy  
30min
Solve question

2. UserInput
C# OOP Public

User interface contains two types of user input controls: TextInput, which accepts all characters and NumericInput, which accepts only digits.

Implement the class TextInput that contains:

  • Public method void Add(char c) - adds the given character to the current value
  • Public method string GetValue() - returns the current value

Implement the class NumericInput that:

  • Inherits TextInput
  • Overrides the Add method so that each non-numeric character is ignored

For example, the following code should output "10":

TextInput input = new NumericInput();
input.Add('1');
input.Add('a');
input.Add('0');
Console.WriteLine(input.GetValue());
Easy  
15min
Solve question

3. Palindrome
C# Strings Public

A palindrome is a word that reads the same backward or forward.

Write a function that checks if a given word is a palindrome. Character case should be ignored.

For example, IsPalindrome("Deleveled") should return true as character case should be ignored, resulting in "deleveled", which is a palindrome since it reads the same backward and forward.

Easy  
10min
Solve question

4. BinarySearchTree
C# Algorithmic thinking Data structures Public

Binary search tree (BST) is a binary tree where the value of each node is larger or equal to the values in all the nodes in that node's left subtree and is smaller than the values in all the nodes in that node's right subtree.

Write a function that checks if a given binary search tree contains a given value.

For example, for the following tree:

  • n1 (Value: 1, Left: null, Right: null)
  • n2 (Value: 2, Left: n1, Right: n3)
  • n3 (Value: 3, Left: null, Right: null)

Call to Contains(n2, 3) should return true since a tree with root at n2 contains number 3.

Easy  
15min
Solve question

5. Path
C# Data structures Strings Public

Write a function that provides change directory (cd) function for an abstract file system.

Notes:

  • Root path is '/'.
  • Path separator is '/'.
  • Parent directory is addressable as "..".
  • Directory names consist only of English alphabet letters (A-Z and a-z).

For example, new Path("/a/b/c/d").Cd("../x").CurrentPath should return "/a/b/c/x".

Note: Do not use built-in path-related functions.

Hard  
30min
Solve question

6. Folders
C# Serialization Public

Implement a function FolderNames, which accepts a string containing an XML file that specifies folder structure and returns all folder names that start with startingLetter. The XML format is given in the example below.

For example, for the letter 'u' and XML file:

<?xml version="1.0" encoding="UTF-8"?>
<folder name="c">
    <folder name="program files">
        <folder name="uninstall information" />
    </folder>
    <folder name="users" />
</folder>

the function should return "uninstall information" and "users" (in any order).

Hard  
20min
Solve question

7. SortedSearch
C# Algorithmic thinking Searching Public

Implement function CountNumbers that accepts a sorted array of integers and counts the number of array elements that are less than the parameter lessThan.

For example, SortedSearch.CountNumbers(new int[] { 1, 3, 5, 7 }, 4) should return 2 because there are two array elements less than 4.

Hard  
20min
Solve question

8. TrainComposition
C# Algorithmic thinking Data structures Public

A TrainComposition is built by attaching and detaching wagons from the left and the right sides.

For example, if we start by attaching wagon 7 from the left followed by attaching wagon 13, again from the left, we get a composition of two wagons (13 and 7 from left to right). Now the first wagon that can be detached from the right is 7 and the first that can be detached from the left is 13.

Implement a TrainComposition that models this problem.

Hard  
20min
Solve question

If you feel ready, take one of our timed public C# interview questions tests:

  • C# online test (Easy / Hard)
  • C# Algorithms online test (Easy / Hard)
  • C# and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, C#, and SQL online test (Easy / Hard)
  • HTML/CSS, JavaScript, SQL, and C# Algorithms online test (Easy / Hard)
  • SQL and C# Algorithms online test (Easy / Hard)
Not exactly what you are looking for? Go to our For developers section.