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

  1. static void Main(string[] args)
  2. {
  3. //Write Program to find fibonacci series for given number
  4. for (int i = 0; i < 10; i++)
  5. {
  6. Console.Write("{0} ", FibbonacciSeries(i));
  7. }
  8. Console.WriteLine(Environment.NewLine);
  9. Console.Write("Fibbonacci Series of {0} is : {1} ", 10, FibbonacciSeries1(10));
  10. Console.WriteLine(Environment.NewLine);
  11. //Write Program to calculate factorial value for given number
  12. Console.WriteLine("The Factorial of {0} is: {1} \n", 6, Factorial(6));
  13. //Write Program to find duplicate in String
  14. FindDuplicateCharacterInString("CSharpCorner");
  15. Console.WriteLine(Environment.NewLine);
  16. //Write Program to find duplicate in string array
  17. FindDuplicateInstringArray();
  18. Console.WriteLine(Environment.NewLine);
  19. //Write Program to Remove duplicate in string
  20. RemoveDuplicate("CSharpCorner");
  21. Console.WriteLine(Environment.NewLine);
  22. //Write Program to find number of character in string
  23. FindNumberofCharaterinString();
  24. Console.WriteLine(Environment.NewLine);
  25. //Write Program to find number of words in string
  26. ReverseStringWords("Jignesh Kumar");
  27. Console.WriteLine(Environment.NewLine);
  28. //Write Program to find consicutive character in string
  29. char[] charArray = { 'A', 'B', 'B', 'C', 'D', 'D', 'E', 'F', 'F' };
  30. FindConsicutiveCharacter(charArray);
  31. Console.WriteLine(Environment.NewLine);
  32. //Write Program to check string is palindrome or not
  33. string[] strArray = { "WOW", "NOON", "ABBA", "ANNA", "BOB", "Jimmy", "Peter" };
  34. foreach (var item in strArray)
  35. {
  36. Console.WriteLine(" {0} Is palindrome {1}", item, IsStringPalindrome(item));
  37. }
  38. Console.WriteLine(Environment.NewLine);
  39. //Write program to check number is palindrome or not
  40. int number = 121;
  41. Console.WriteLine("{0} is Palindrome number {1} ", number, IsNumberPalindrome(number));
  42. Console.WriteLine(Environment.NewLine);
  43. //Write program to check number is palindrome or not
  44. number = 127;
  45. Console.WriteLine("{0} is prime number {1} ", number, IsNumberPrime(number));
  46. number = 128;
  47. Console.WriteLine("{0} is prime number {1} ", number, IsNumberPrime(number));
  48. Console.ReadLine();
  49. }

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

  1. private static int FibbonacciSeries(int number)
  2. {
  3. int firstValue = 0;
  4. int secondValue = 1;
  5. int result = 0;
  6. if (number == 0)
  7. return 0;
  8. if (number == 1)
  9. 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;
  17. }
  18. public static string FibbonacciSeries1(int n)
  19. {
  20. int a = 0, b = 1, c;
  21. StringBuilder sb = new StringBuilder();
  22. for (int i = 1; i < n; i++)
  23. {
  24. sb.Append(a.ToString() + ",");
  25. c = a + b;
  26. a = b;
  27. b = c;
  28. }
  29. return sb.ToString().Remove(sb.Length - 1); ;
  30. }

Write a program to calculate factorial value for a given number

  1. private static int Factorial(int number)
  2. {
  3. int fact = 1;
  4. if (number == 0)
  5. return 0;
  6. if (number == 1)
  7. return 1;
  8. for (int i = 1; i <= number; i++)
  9. {
  10. fact = fact * i;
  11. }
  12. return fact;
  13. }

Write a program to find duplicate in String

  1. private static void FindDuplicateCharacterInString(string inPutString)
  2. {
  3. if (string.IsNullOrEmpty(inPutString))
  4. {
  5. Console.WriteLine("Please enter valid Input");
  6. }
  7. else
  8. {
  9. var list = new List<char>();
  10. string result = string.Empty;
  11. foreach (char item in inPutString)
  12. {
  13. if (list.Contains(item))
  14. {
  15. if (!result.Contains(item))
  16. result += item;
  17. }
  18. else
  19. {
  20. list.Add(item);
  21. }
  22. }
  23. Console.WriteLine("Duplicate Found : {0} ", result);
  24. }
  25. }

Write a program to find duplicate in a string array

  1. public static void FindDuplicateInstringArray()
  2. {
  3. string[] strArray = { "Sunday", "Monday", "Tuesday", "Wednesday", "Sunday", "Monday" };
  4. List<string> lstString = new List<string>();
  5. StringBuilder sb = new StringBuilder();
  6. foreach (var str in strArray)
  7. {
  8. if (lstString.Contains(str))
  9. {
  10. sb.Append(" " + str);
  11. }
  12. else
  13. {
  14. lstString.Add(str);
  15. }
  16. }
  17. Console.WriteLine("Duplicate Found : {0}", sb.ToString());
  18. }
Write a program to remove duplicate in string:
  1. public static void RemoveDuplicate(string inputString)
  2. {
  3. var list = new List<char>();
  4. foreach (var item in inputString)
  5. {
  6. if (!list.Contains(item))
  7. {
  8. list.Add(item);
  9. }
  10. }
  11. Console.WriteLine("Orignal String {0}, After duplicate removed {1}", inputString, new string(list.ToArray()));
  12. }

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

  1. public static void FindNumberofCharaterinString()
  2. {
  3. string StringToCount = "DotNetDeveloper";
  4. var result = FindOccuranceofCharacterInString(StringToCount);
  5. Console.WriteLine("Number of occurrences of a character in given string");
  6. foreach (var count in result)
  7. {
  8. Console.WriteLine(" {0} - {1} ", count.Key, count.Value);
  9. }
  10. }
  11. public static SortedDictionary<char, int> FindOccuranceofCharacterInString(string str)
  12. {
  13. SortedDictionary<char, int> count = new SortedDictionary<char, int>();
  14. foreach (var chr in str)
  15. {
  16. if (!(count.ContainsKey(chr)))
  17. {
  18. count.Add(chr, 1);
  19. }
  20. else
  21. {
  22. count[chr]++;
  23. }
  24. }
  25. return count;
  26. }

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

  1. public static void ReverseStringWords(string inputString)
  2. {
  3. string[] seprator = { " " };
  4. string[] words = inputString.Split(seprator, StringSplitOptions.RemoveEmptyEntries);
  5. string result = string.Empty;
  6. for (int i = words.Length - 1; i >= 0; i--)
  7. {
  8. result += words[i].ToString();
  9. }
  10. Console.WriteLine("Reverse words in string {0}", result);
  11. }

Write a program to find the consecutive characters in a string

  1. public static void FindConsicutiveCharacter(char[] characterArray)
  2. {
  3. int len = characterArray.Length - 1;
  4. List<char> result = new List<char>();
  5. for (int i = 0; i < len; i++)
  6. {
  7. for (int j = i + 1; j <= len; j++)
  8. {
  9. 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. Console.WriteLine("Consicutive Character found {0} ", new string(result.ToArray()));
  22. }

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

  1. public static bool IsStringPalindrome(string inputString)
  2. {
  3. int minIdex = 0;
  4. int maxIdex = inputString.Length - 1;
  5. while (true)
  6. {
  7. if (minIdex > maxIdex)
  8. {
  9. 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;
  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

  1. public static bool IsNumberPrime(int number)
  2. {
  3. int i;
  4. for (i = 2; i <= number - 1; i++)
  5. {
  6. if (number % i == 0)
  7. {
  8. return false;
  9. }
  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