0% found this document useful (0 votes)
65 views

01 Top C# .NET Coding Questions with Solutions - Interview Preparation Guide

Uploaded by

Arafat Zaman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

01 Top C# .NET Coding Questions with Solutions - Interview Preparation Guide

Uploaded by

Arafat Zaman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

12/2/24, 2:10 PM Top C# .

NET Coding Questions with Solutions - Interview Preparation Guide | LinkedIn

Reactivate Prem
Home My Network Jobs Messaging Notifications Me For Business 50% Off

DotNet Guru
Subscribed
3,164 subscribers

Top C# .NET Coding Questions with Solutions - Interview Preparation Guide

Top C# .NET Coding Questions with


Solutions - Interview Preparation
Guide
Asharib Kamal
Sr. Full Stack Developer | Specializing in .NET
Technologies | C# | Dot NET Core | Asp.NET MVC |…

June 11, 2024

In job interviews, especially for C# .NET positions, coding questions are a


common way to assess a candidate's problem-solving skills and coding
proficiency. Here, we will cover some frequently asked coding questions,
provide solutions, and guide you step-by-step on how to solve these
problems. This article aims to help you prepare effectively for your next
interview.

1. Remove Repeated Elements in an Array

Problem Statement: Given an array of integers, remove the duplicate


elements and return the array with unique elements.

Solution:

1. Use a HashSet to store unique elements.

2. Iterate through the array and add elements to the HashSet.

3. Convert the HashSet back to an array.

Code Example:

using System;

using System.Collections.Generic;

public class RemoveDuplicates

https://www.linkedin.com/pulse/top-c-net-coding-questions-solutions-interview-guide-asharib-kamal-hfi8f/ 1/8
12/2/24, 2:10 PM Top C# .NET Coding Questions with Solutions - Interview Preparation Guide | LinkedIn

public static int[] RemoveRepeatedElements(int[]


arr)

HashSet<int> uniqueElements = new


HashSet<int>(arr);

return new int[uniqueElements.Count];

public static void Main()

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

int[] result = RemoveRepeatedElements(arr);

Console.WriteLine("Array with unique


elements: " + string.Join(", ", result));

Step-by-Step Guide:

1. Create a HashSet to store unique elements.

2. Iterate through the given array and add each element to the HashSet.

3. Convert the HashSet to an array and return it.

2. Reverse a String

Problem Statement: Given a string, reverse the string and return the result.

Solution:

1. Convert the string to a character array.

2. Reverse the character array.

3. Convert the character array back to a string.

Code Example:

using System;

public class ReverseString

public static string Reverse(string str)

char[] charArray = str.ToCharArray();

https://www.linkedin.com/pulse/top-c-net-coding-questions-solutions-interview-guide-asharib-kamal-hfi8f/ 2/8
12/2/24, 2:10 PM Top C# .NET Coding Questions with Solutions - Interview Preparation Guide | LinkedIn

Array.Reverse(charArray);

return new string(charArray);

public static void Main()

string str = "hello";

string reversedStr = Reverse(str);

Console.WriteLine("Reversed string: " +


reversedStr);

Step-by-Step Guide:

1. Convert the string to a character array using ToCharArray().

2. Use Array.Reverse() to reverse the character array.

3. Convert the reversed character array back to a string using the new
string() constructor.

3. Find the Maximum Element in an Array

Problem Statement: Given an array of integers, find the maximum


element.

Solution:

1. Iterate through the array and keep track of the maximum element
found.

Code Example:

using System;

public class FindMaxElement

public static int FindMax(int[] arr)

int max = arr[0];

foreach (int num in arr)

if (num > max)

https://www.linkedin.com/pulse/top-c-net-coding-questions-solutions-interview-guide-asharib-kamal-hfi8f/ 3/8
12/2/24, 2:10 PM Top C# .NET Coding Questions with Solutions - Interview Preparation Guide | LinkedIn

max = num;

return max;

public static void Main()

int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

int max = FindMax(arr);

Console.WriteLine("Maximum element: " +


max);

Step-by-Step Guide:

1. Initialize a variable to store the maximum element with the first element
of the array.

2. Iterate through the array and update the maximum variable whenever a
larger element is found.

3. Return the maximum element.

4. Check if a String is a Palindrome

Problem Statement: Given a string, determine if it is a palindrome (reads


the same forward and backward).

Solution:

1. Compare characters from the beginning and end of the string moving
towards the center.

Code Example:

using System;

public class PalindromeCheck

public static bool IsPalindrome(string str)

https://www.linkedin.com/pulse/top-c-net-coding-questions-solutions-interview-guide-asharib-kamal-hfi8f/ 4/8
12/2/24, 2:10 PM Top C# .NET Coding Questions with Solutions - Interview Preparation Guide | LinkedIn
int left = 0;

int right = str.Length - 1;

while (left < right)

if (str[left] != str[right])

return false;

left++;

right--;

return true;

public static void Main()

string str = "racecar";

bool isPalindrome = IsPalindrome(str);

Console.WriteLine("Is palindrome: " +


isPalindrome);

Step-by-Step Guide:

1. Initialize two pointers, one at the beginning (`left`) and one at the end
(`right`) of the string.

2. Compare characters at these pointers and move towards the center.

3. If all characters match, the string is a palindrome.

5. Sum of Elements in an Array

Problem Statement: Given an array of integers, find the sum of all


elements.

Solution:

1. Iterate through the array and accumulate the sum.

Code Example:

https://www.linkedin.com/pulse/top-c-net-coding-questions-solutions-interview-guide-asharib-kamal-hfi8f/ 5/8
12/2/24, 2:10 PM Top C# .NET Coding Questions with Solutions - Interview Preparation Guide | LinkedIn

using System;

public class SumOfElements

public static int Sum(int[] arr)

int sum = 0;

foreach (int num in arr)

sum += num;

return sum;

public static void Main()

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

int sum = Sum(arr);

Console.WriteLine("Sum of elements: " +


sum);

Step-by-Step Guide:

1. Initialize a variable to store the sum.

2. Iterate through the array and add each element to the sum variable.

3. Return the sum.

### SEO Title and Description

SEO Title: Top C# .NET Coding Questions with Solutions - Interview


Preparation Guide

SEO Description: Prepare for your C# .NET interview with our guide
covering top coding questions and solutions. Learn step-by-step how to
solve common problems and ace your technical interview.

#DotNet #CSharp #CodingInterview #InterviewPreparation #Programming


#SoftwareDevelopment #DotNetGuru #TechCareer #InterviewTips"

https://www.linkedin.com/pulse/top-c-net-coding-questions-solutions-interview-guide-asharib-kamal-hfi8f/ 6/8
12/2/24, 2:10 PM Top C# .NET Coding Questions with Solutions - Interview Preparation Guide | LinkedIn

Report this article

Comments

8· 1 comment

Like Comment Share

Add a comment…

Most relevant

Steve Todd • 3rd+ 3mo


Looking for a new role

Is there a reason why LINQ isn't being used for these problems?
Question 3 for example is a single LINQ statement ( return arr.Max(); )

Like Reply

DotNet Guru
Unlock your coding potential with DotNet Guru! Dive into daily .NET tips, tricks and career
inspiration. Subscribe now!

Rafsanul, Aram and 1 connections are subscribed

3,164 subscribers

Subscribed

More articles for you

Mastering .NET Interview: Essential Tips & How to learn to solve coding interview Mastering Technical Interviews: "6
Questions questions using Leetcode (Part I) Platforms to Boost Your Coding Skills and
DotNet Guru Omar Ismail Ace Your Next Job Interview"​
JOBMINAR Consultants
5 · 1 repost 27 · 1 comment · 3 reposts
7

About Accessibility Talent Solutions Questions? Select Language


Visit our Help Center.
Professional Community Policies Careers Marketing Solutions English (English)

Privacy & Terms Ad Choices Advertising Manage your account and privacy
Go to your Settings.
Sales Solutions Mobile Small Business

Safety Center
Recommendation transparency
Learn more about Recommended Content.

https://www.linkedin.com/pulse/top-c-net-coding-questions-solutions-interview-guide-asharib-kamal-hfi8f/ 7/8
12/2/24, 2:10 PM Top C# .NET Coding Questions with Solutions - Interview Preparation Guide | LinkedIn
LinkedIn Corporation © 2024

https://www.linkedin.com/pulse/top-c-net-coding-questions-solutions-interview-guide-asharib-kamal-hfi8f/ 8/8

You might also like