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

03 Common Coding Interview Questions For .NET Interview

Uploaded by

Arafat Zaman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

03 Common Coding Interview Questions For .NET Interview

Uploaded by

Arafat Zaman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

12/2/24, 2:17 PM Common Coding Interview Questions For .

NET Interview

Common Coding Interview Questions For .NET


Interview
Jignesh Kumar Jun 25, 2019 100k 2 17

TechnicalInterviewQuestion.zip

This article explains commonly asked coding example questions in technical rounds for .NET
interviews. Here, I have given some examples with the code to help the developers prepare for a
technical interview. It looks simple but during the interview, it will be difficult to explain or write on
paper.

I have attached the source code with this article for all the below examples.

Common programs to build that interviewers ask during .NET


interviews
01. static void Main(string[] args)
02. {
03. //Write Program to find fibonacci series for given number
04. for (int i = 0; i < 10; i++)
05. {
06. Console.Write("{0} ", FibbonacciSeries(i));
07. }
08. Console.WriteLine(Environment.NewLine);
09.
10. Console.Write("Fibbonacci Series of {0} is : {1} ", 10, Fibbon
11.
12. Console.WriteLine(Environment.NewLine);
13.
14. //Write Program to calculate factorial value for given number
15. Console.WriteLine("The Factorial of {0} is: {1} \n", 6, Factor
16.
17. //Write Program to find duplicate in String
18. FindDuplicateCharacterInString("CSharpCorner");
19.
20. Console.WriteLine(Environment.NewLine);
21. //Write Program to find duplicate in string array
22. FindDuplicateInstringArray();
23.
24. Console.WriteLine(Environment.NewLine);
25. //Write Program to Remove duplicate in string
26. RemoveDuplicate("CSharpCorner");
27.
28. Console.WriteLine(Environment.NewLine);
29. //Write Program to find number of character in string
30. FindNumberofCharaterinString();
https://www.c-sharpcorner.com/article/net-programing-interview-questions/ 1/10
12/2/24, 2:17 PM Common Coding Interview Questions For .NET Interview

31.
32. Console.WriteLine(Environment.NewLine);
33. //Write Program to find number of words in string
34. ReverseStringWords("Jignesh Kumar");
35.
36. Console.WriteLine(Environment.NewLine);
37. //Write Program to find consicutive character in string
38. char[] charArray = { 'A', 'B', 'B', 'C', 'D', 'D', 'E', 'F', '
39. FindConsicutiveCharacter(charArray);
40.
41. Console.WriteLine(Environment.NewLine);
42. //Write Program to check string is palindrome or not
43. string[] strArray = { "WOW", "NOON", "ABBA", "ANNA", "BOB", "J
44.
45. foreach (var item in strArray)
46. {
47. Console.WriteLine(" {0} Is palindrome {1}", item, IsString
48. }
49.
50. Console.WriteLine(Environment.NewLine);
51. //Write program to check number is palindrome or not
52. int number = 121;
53. Console.WriteLine("
{0} is Palindrome number {1} ", number, IsNumberPalindrome(number));
54.
55. Console.WriteLine(Environment.NewLine);
56. //Write program to check number is palindrome or not
57. number = 127;
58. Console.WriteLine("
{0} is prime number {1} ", number, IsNumberPrime(number));
59. number = 128;
60. Console.WriteLine("
{0} is prime number {1} ", number, IsNumberPrime(number));
61. Console.ReadLine();
62. }

Write a program for printing a fibonacci series for a given number


01. private static int FibbonacciSeries(int number)
02. {
03. int firstValue = 0;
04. int secondValue = 1;
05. int result = 0;
06. if (number == 0)
07. return 0;
08. if (number == 1)
09. return 1;
10. for (int i = 2; i <= number; i++)
11. {
12. result = firstValue + secondValue;
13. firstValue = secondValue;
14. secondValue = result;
15. }
16. return result;
https://www.c-sharpcorner.com/article/net-programing-interview-questions/ 2/10
12/2/24, 2:17 PM Common Coding Interview Questions For .NET Interview

17. }
18.
19. public static string FibbonacciSeries1(int n)
20. {
21. int a = 0, b = 1, c;
22. StringBuilder sb = new StringBuilder();
23. for (int i = 1; i < n; i++)
24. {
25. sb.Append(a.ToString() + ",");
26. c = a + b;
27. a = b;
28. b = c;
29. }
30. return sb.ToString().Remove(sb.Length - 1); ;
31. }
Write a program to calculate factorial value for a given number
01. private static int Factorial(int number)
02. {
03. int fact = 1;
04. if (number == 0)
05. return 0;
06. if (number == 1)
07. return 1;
08.
09. for (int i = 1; i <= number; i++)
10. {
11. fact = fact * i;
12. }
13. return fact;
14. }

Write a program to find duplicate in String


01. private static void FindDuplicateCharacterInString(string inPutString)
02. {
03.
04. if (string.IsNullOrEmpty(inPutString))
05. {
06. Console.WriteLine("Please enter valid Input");
07. }
08. else
09. {
10. var list = new List<char>();
11. string result = string.Empty;
12.
13. foreach (char item in inPutString)
14. {
15. if (list.Contains(item))
16. {
17. if (!result.Contains(item))
18. result += item;
19. }
https://www.c-sharpcorner.com/article/net-programing-interview-questions/ 3/10
12/2/24, 2:17 PM Common Coding Interview Questions For .NET Interview

20. else
21. {
22. list.Add(item);
23. }
24. }
25. Console.WriteLine("Duplicate Found : {0} ", result);
26. }
27. }

Write a program to find duplicate in a string array


01. public static void FindDuplicateInstringArray()
02. {
03. string[] strArray = { "Sunday", "Monday", "Tuesday", "Wednesda
04. List<string> lstString = new List<string>();
05. StringBuilder sb = new StringBuilder();
06.
07. foreach (var str in strArray)
08. {
09. if (lstString.Contains(str))
10. {
11. sb.Append(" " + str);
12.
13. }
14. else
15. {
16. lstString.Add(str);
17. }
18. }
19. Console.WriteLine("Duplicate Found : {0}", sb.ToString());
20. }

Write a program to remove duplicate in string:

01. public static void RemoveDuplicate(string inputString)


02. {
03. var list = new List<char>();
04.
05. foreach (var item in inputString)
06. {
07. if (!list.Contains(item))
08. {
09. list.Add(item);
10. }
11. }
12.
13.
Console.WriteLine("Orignal String {0}, After duplicate removed {1}", input
14. }

Write a program to find a number of character in a string


https://www.c-sharpcorner.com/article/net-programing-interview-questions/ 4/10
12/2/24, 2:17 PM Common Coding Interview Questions For .NET Interview

01. public static void FindNumberofCharaterinString()


02. {
03. string StringToCount = "DotNetDeveloper";
04. var result = FindOccuranceofCharacterInString(StringToCount);
05.
06. Console.WriteLine("Number of occurrences of a character in giv
07. foreach (var count in result)
08. {
09. Console.WriteLine(" {0} -
{1} ", count.Key, count.Value);
10. }
11. }
12.
13. public static SortedDictionary<char, int> FindOccuranceofCharacterInString
14. {
15. SortedDictionary<char, int> count = new SortedDictionary<char, int>
();
16.
17. foreach (var chr in str)
18. {
19. if (!(count.ContainsKey(chr)))
20. {
21. count.Add(chr, 1);
22. }
23. else
24. {
25. count[chr]++;
26. }
27. }
28.
29. return count;
30. }

Write a program to find a number of words in a string


01. public static void ReverseStringWords(string inputString)
02. {
03. string[] seprator = { " " };
04. string[] words = inputString.Split(seprator, StringSplitOption
05. string result = string.Empty;
06. for (int i = words.Length - 1; i >= 0; i--)
07. {
08. result += words[i].ToString();
09. }
10. Console.WriteLine("Reverse words in string {0}", result);
11. }

Write a program to find the consecutive characters in a string


01. public static void FindConsicutiveCharacter(char[] characterArray)
02. {
https://www.c-sharpcorner.com/article/net-programing-interview-questions/ 5/10
12/2/24, 2:17 PM Common Coding Interview Questions For .NET Interview

03. int len = characterArray.Length - 1;


04. List<char> result = new List<char>();
05. for (int i = 0; i < len; i++)
06. {
07. for (int j = i + 1; j <= len; j++)
08. {
09. if (characterArray[i] == characterArray[j])
10. {
11. if (!result.Contains(characterArray[i]))
12. result.Add(characterArray[i]);
13. continue;
14. }
15. else
16. {
17. break;
18. }
19. }
20. }
21.
22. Console.WriteLine("Consicutive Character found {0} ", new strin
23. }

Write a program to check if a string/number is a palindrome or not


01. public static bool IsStringPalindrome(string inputString)
02. {
03. int minIdex = 0;
04. int maxIdex = inputString.Length - 1;
05. while (true)
06. {
07. if (minIdex > maxIdex)
08. {
09. return true;
10. }
11. char charfromLeft = inputString[minIdex];
12. char charfromRight = inputString[maxIdex];
13. if (charfromLeft != charfromRight)
14. {
15. return false;
16. }
17. minIdex++;
18. maxIdex--;
19. }
20. }
21. public static bool IsNumberPalindrome(int number)
22. {
23. int reminder, sum = 0;
24. int tempNumber;
25. tempNumber = number;
26. bool IsPalindrome = false;
27. while (number > 0)
28. {
29. reminder = number % 10;
30. number = number / 10;
https://www.c-sharpcorner.com/article/net-programing-interview-questions/ 6/10
12/2/24, 2:17 PM Common Coding Interview Questions For .NET Interview

31. sum = sum * 10 + reminder;


32. if (tempNumber == sum)
33. {
34. IsPalindrome = true;
35. }
36. }
37. return IsPalindrome;
38. }
Write a program to check if a number is prime or not
01. public static bool IsNumberPrime(int number)
02. {
03. int i;
04. for (i = 2; i <= number - 1; i++)
05. {
06. if (number % i == 0)
07. {
08. return false;
09. }
10. }
11. if (i == number)
12. {
13. return true;
14. }
15. return false;
16. }

Please find my other articles if you wish to read more about .NET and other cutting-edge
technologies.

Swagger UI Integration With Web API For Testing And Documentation Click Here
Tricks and Tips In Visual Studio To Speed Up Your Code Using Default Code Snippet
Feature Click Here
Create Documentation With Sandcastle Help Builder Click Here
Test Web API using SoapUI Click Here
Getting Started with TypeScript Click Here
LINQ extension methods Click Here

.Net Interview Question Code Example Interview preparation Interview Question

RECOMMENDED FREE EBOOK

https://www.c-sharpcorner.com/article/net-programing-interview-questions/ 7/10
12/2/24, 2:17 PM Common Coding Interview Questions For .NET Interview

DateTime in C#

Download Now!

SIMILAR ARTICLES

Important SQL Server Interview Questions

Important Questions For Interview C# Part 1 - Basics

SharePoint 2013: Frequently Asked Comparison Interview Questions

Top Frequently Asked Questions in .Net Interview

Common Angular Interview Questions And Answers

Jignesh Kumar
Tech Lead | Blogger | Content Creator | Full Stack Developer | 6 time C# Corner MVP
https://www.techjigs.com

32 2.8m 6

View All Comments


2

Type your comment here and press Enter Key (Minimum 10 characters)

https://www.c-sharpcorner.com/article/net-programing-interview-questions/ 8/10
12/2/24, 2:17 PM Common Coding Interview Questions For .NET Interview

https://www.c-sharpcorner.com/article/net-programing-interview-questions/ 9/10
12/2/24, 2:17 PM Common Coding Interview Questions For .NET Interview

About Us Contact Us Privacy Policy Terms Media Kit Sitemap Report a Bug FAQ Partners

C# Tutorials Common Interview Questions Stories Consultants Ideas Certifications CSharp TV

Web3 Universe Build with JavaScript Let's React DB Talks Jumpstart Blockchain Interviews.help
©2024 C# Corner. All contents are copyright of their authors.

https://www.c-sharpcorner.com/article/net-programing-interview-questions/ 10/10

You might also like