C# Interview Questions

C# Interview Questions

In this article, I will share my ASP.NET C# interview experience with Questions and Answers.

C# Interview Questions


1. What is Polymorphism in C# OOPs?

  • The word Polymorphism means "One Name Many Forms".   
  • In the object-oriented programming paradigm, polymorphism is often expressed as 'one interface, multiple functions' or 'one name with multiple functionalities'
  • There are two types of polymorphism in C# - Static / Compile Time Polymorphism & Dynamic / Runtime Polymorphism.
  • Static or Compile Time Polymorphism is also known as Early Binding. Method overloading is an example of Static Polymorphism
  • Dynamic / Runtime Polymorphism is also known as late binding. Method overriding is an example of dynamic polymorphism.


2. How can you remove duplicate characters in a string?

The below program will remove the duplicate characters in a string.


using System;
using System.Linq;
using System.Collections.Generic;

namespace Demo {
   class Program {
      
      static void Main(string[] args) 
      {
          
         string value1 = RemoveDuplicateChars("aayryrtfhbfss");
            Console.Write(value1);   
      }
      
       static string RemoveDuplicateChars(string key)
    {
        string result = "";          
        foreach (char value in key)
        {
            // result.IndexOf(value) will give the position of the Character in a string, if Character not exist will return -1
            if (result.IndexOf(value) == -1)                   
                result += value;
                
        }
        return result;
    }
    
      
   }
}



I hope this post will help you. Please put your feedback using comments which will help me to improve myself for the next post. If you have any doubts or queries, please ask in the comments section and if you like this post, please share it with your friends. Thanks!

0 Comments