30 C# Basic Exercises for Advanced with Solutions
Master advanced C# skills with our comprehensive list of top 30 exercises. Dive into coding challenges that improve your understanding and proficiency in C#, setting a solid foundation for professional-level challenges. Start your journey to C# mastery today!
Learning Objectives:
Master advanced C# skills with our comprehensive list of top 30 exercises. Dive into coding challenges that improve your understanding and proficiency in C#, setting a solid foundation for professional-level challenges. Start your journey to C# mastery today!
Exercise Instructions:
- Start with the first exercise and attempt to solve it before checking the hint or solution.
- Ensure you understand the logic behind each solution, as this will help you in more complex problems.
- Use these exercises to reinforce your learning and identify areas that may require further study.
1. Write a program to solve the N-Queens problem for a hardcoded board size (e.g., 8x8).
Required Input:
Board Size: 8
Expected Output:
1 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0
Code In C#
Run Code?
Click Run Button to view compiled output
2. Create a program to implement the Dijkstra algorithm for finding the shortest path in a graph.
Required Input:
Graph: { "nodes": [0, 1, 2], "edges": [[0, 1, 4], [0, 2, 1], [2, 1, 2]] }
Expected Output:
Vertex Distance from Source
0 0
1 4
2 1
Code In C#
Run Code?
Click Run Button to view compiled output
3. Write a program to create a custom stack class with a GetMin() method to retrieve the minimum element in constant time.
Required Input:
Operations: Push(5), Push(3), Push(7), Pop(), GetMin()
Expected Output:
Minimum Element: 3
Code In C#
Run Code?
Click Run Button to view compiled output
4. Create a program to implement a simple file system explorer using recursion to traverse directories.
Required Input:
Directory Path: "C:/Example"
Expected Output:
Directory does not exist.
Code In C#
Run Code?
Click Run Button to view compiled output
5. Create a program to implement a basic thread-safe Singleton design pattern.
Required Input:
Class Instance Request: Multiple calls to GetInstance()
Expected Output:
Singleton instance created.
Singleton instance in action.
Singleton instance in action.
Same instance
Code In C#
Run Code?
Click Run Button to view compiled output
6. Write a program to calculate the Levenshtein distance between two strings.
Required Input:
Strings: "kitten" and "sitting"
Expected Output:
Levenshtein Distance: 3
Code In C#
Run Code?
Click Run Button to view compiled output
7. Create a program to generate a Pascal’s Triangle for a hardcoded number of rows.
Required Input:
Rows: 5
Expected Output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Code In C#
Run Code?
Click Run Button to view compiled output
8. Write a program to implement the QuickSort algorithm on a hardcoded array.
Required Input:
Array: [5, 3, 8, 6, 2]
Expected Output:
Sorted Array: 2, 3, 5, 6, 8
Code In C#
Run Code?
Click Run Button to view compiled output
9. Create a program to find the largest rectangle area in a histogram represented as an array.
Required Input:
Heights: 2, 1, 5, 6, 2, 3
Expected Output:
Largest Rectangle Area: 10
Code In C#
Run Code?
Click Run Button to view compiled output
10. Write a program to validate an XML string against a schema (XSD).
Required Input:
XML: <person><name>John</name><age>30</age></person> XSD: Schema definition provided in the problem.
Expected Output:
XML is valid: True
Code In C#
Run Code?
Click Run Button to view compiled output