C# Interview Questions

Showing Questions 1 - 20 of 529 Questions
First | Prev | Next | Last Page
Sort by: 
Jump to Page:

    Is it possible to have different access modifiers on the get/set methods of a property? Justify

    S Manasa

    • Jul 8th, 2019

    Generally, the access modifier of the property is considered as the access modifier of both the accessors if no access modifier is specified for the accessors. Only one of the accessor can be specifi...


    How many types of Inheritance is there in C#?


    Can youplz tell me how many types of Inheritance is there in C#?
    As per my knowledge these are following but i am not sure
    -single level
    -multi level
    -Hierarchical inheritence
    -Hybride inheritence.
    there one more inheritence but its not suported by C# that is Multiple inheritence.
    is it correct ?plz help me.

    Kajul Nisha

    • Jun 14th, 2019

    As per my knowledge, C# supports the following inheritance
    1. single
    it doesn't support multiple inheritance
    but it can be achieved by interfaces


    Can you change the value of a variable while debugging a C# application?

    Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.


    • Apr 4th, 2019

    yes, we can! The simplest way I prefer is - 1. Hover on the variable you want to edit the value of. 2. It will show a small window with value, right click on it and select Add watch. 3. A new tab ...


    • May 17th, 2016

    Yes you can!


    Is it possible to inherit a class that has only private constructor?


    • Feb 18th, 2019

    Nope. We cant inherit a class if it has Private constructor.

    Vikas Kumar Bhatnagar

    • Aug 14th, 2018

    We cant inherit the abstract class and when we declared a class as abstract and define the private constructor .
    Following compilation error:
    Cannot create an instance of the abstract class or interface Singleton.
    Singleton.Singleton() is inaccessible due to its protection level


    Divide Two Numbers Without Using Division and Modulus Operator

    Write C# code to divide two numbers without using the division and modulus operator


    • Feb 18th, 2019

    Keep on subtracting divisor from dividend until dividend is 0 and return the count as quotient.

    Pushpa Sundar

    • Mar 16th, 2018

    "java import java.util.Scanner; public class Divition { public static void main(String[] args) { Scanner scn=new Scanner(System.in); System.out.println("Enter the Divi...


    Is it mandatory to implement all the methods which are there in abstract class if we inherit that abstract class..?

    Abhijeet Gawali

    • Apr 20th, 2018

    Yes, if u Create Abstract class one or more abstract method in class. If after inherit Abstract Class all abstract methods are compulsory/Mandatory implemented in derived class., otherwise they gene...


    C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?

    Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there's no implementation in it.


    • Oct 26th, 2017

    One constructor is enough. In every constructor program we can't create number of constructor. We can create the number of classes in constructor. so here we can give parameters in method only we can declare the parameters.


    • Nov 18th, 2006

    Hi,In C#.Net we can have multiple constructors.Before going any further I think you need to know a liitle bit about the constructors. ...


    Are private class-level variables inherited?

    Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

    Rajendra Mahakali

    • Jun 29th, 2017

    YES, But they are accessible. Although they are not visible or accessible, but YES they are inherited.


    Debug C# Web Application

    How to debug C# Web Application?

    Samwise Galenorn

    • Nov 25th, 2016

    To debug C# Web App, you need Visual Studio, and a local IIS Server 6.0 or above. First, load the code into Visual Studio, next fire up the worker process by invoking the web app. Once the worker proc...


    • Mar 3rd, 2016

    Use Firebug for Firefox


    Advantage of avl tree over binary search tree.

    What is advantage using avl tree instead of using binary search tree ?


    • Nov 23rd, 2016

    In BST, the time complexity of search operation (average case) is taken to be O(log n). But in the worst case, i.e the degenerate trees/skewed trees time complexity of search operation is O(n) which c...


    • Sep 8th, 2015

    Better search times for keys


    How to upload a file in c# console application

    sandya Kolipaka

    • Nov 10th, 2016

    Static void Main(string[] args)
    var wc = new WebClient();
    byte[] response = wc.UploadFile("http:// mysite . com/Tests/Test", "POST", "teste.xml");
    string s = System.Text.Encoding.ASCII.GetString(response);


    • Feb 15th, 2007

    Use System.Net.WebClient Class use UploadFile method provided by the class. It accepts the Uri or string as destination and another parameter as location of file to be uploaded.


    Only a 'Static' method can be called using delegate - True / False? Give Reason

    Naveen Shivanadri

    • Sep 18th, 2016

    Using delegate, we can execute static method as well as instance method. By binding a method with delegate, we will use the instance if the method is instance method else method name if the method is static.



    Multicast Delegate

    What is multicast delegate? When it is used?

    Naveen Shivanadri

    • Sep 18th, 2016

    Multicast delegate is useful when the application has many methods (each method for each purpose) which are no return type (void) and those methods are using same parameter. In this case we will use ...

    Reeshabh Choudhary

    • Nov 4th, 2015

    A useful property of delegate objects is that multiple objects can be assigned to one delegate instance by using the + operator. The multicast delegate contains a list of the assigned delegates. When...


    How do I create a Delegate/MulticastDelegate?

    C# requires only a single parameter for delegates: the method address. Unlike other languages, where the programmer must specify an object reference and the method to invoke, C# can infer both pieces of information by just specifying the method's name. For example, let's use System.Threading.ThreadStart: Foo MyFoo = new Foo();ThreadStart del = new ThreadStart(MyFoo.Baz);This means that delegates can...

    Star Read Best Answer

    Editorial / Best Answer

    Answered by: Raghu

    • Sep 29th, 2005

    This article is good.


    In this article I am going to share my knowledge on Delegates in C#.This would explain the Delegate using simple examples so that the beginner can understand the same.

    What is Delegate?


    Delegate is type which  holds the method(s) reference in an object.
    it is also reffered as a type safe function pointers.

    .Encapsulating the method's call from caller
    .Effective use of Delegat improves the performance of application.
    .used to call a method asynchronously.


    public delegate type_of_delegate delegate_name()

    Example : public delegate int mydelegate(int delvar1,int delvar2)

    .you can use delegeate without parameter or with parameter list
    .you should follow the same syntax as in the method
    (if you are reffering the method with two int parameters and int return type the delegate which you are declaring should be the same format.This is how it
    is reffered as type safe function pointer)

    Sample Program using Delegate :

    public delegate double Delegate_Prod(int a,int b);

    class Class1

    static double fn_Prodvalues(int val1,int val2)
    return val1*val2;
    static void Main(string[] args)

    //Creating the Delegate Instance
    Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);

    Console.Write("Please Enter Values");

    int v1 = Int32.Parse(Console.ReadLine());
    int v2 = Int32.Parse(Console.ReadLine());

    //use a delegate for processing

    double res = delObj(v1,v2);
    Console.WriteLine ("Result :"+res);



    Here I have used a small program which demonstrates the use of delegate.

    The delegate "Delegate_Prod" is declared with double return type and which accepts only two integer parameters.

    Inside the Class the method named fn_Prodvalues is defined with double return type and two integer parameters.(The delegate and method is having the same signature and parameters type)

    Inside the Main method the delegate instance is created and the function name is passed to the
    delegate instance as following.

    Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);

    After this we are accepting the two values from the user and passing those values to the delegate as we do using method .


    Here  delegate object encapsulates the method functionalities and return the result as we specified
    in the method.

    Multicast Delegate

    What is Multicast Delegate? :
    It is a Delegate which holds the reference of more than one methods.
    Multicast delegates must contain only methods that return void, else there is a run-time exception.

    Simple Program using Multicast Delegate

    delegate void Delegate_Multicast(int x, int y);

    Class Class2

    static void Method1(int x, int y) {
     Console.WriteLine("You r in Method 1");
    static void Method2(int x, int y) {
     Console.WriteLine("You r in Method 2");
    public static void Main()
     Delegate_Multicast func = new Delegate_Multicast(Method1);

     func += new Delegate_Multicast(Method2);
     func(1,2);             // Method1 and Method2 are called
     func -= new Delegate_Multicast(Method1);
     func(2,3);             // Only Method2 is called



    In the above example you can see that two methods are defined named method1 and method2 which takes two integer parameters and return type as void.

    In the main method the Delegate object is created using the following statement

    Delegate_Multicast func = new Delegate_Multicast(Method1);

    Then the Delegate is added using the += operator and removed using -= operator.

    Naveen Kumar Shivanadri

    • Sep 8th, 2016

    Delegate is not type. It is just pointer method which is used to improve the performance. Suppose we want to execute a method 10 times by using calling method by using class name or instance, 10 time...

    Rajesh Muurya

    • Aug 9th, 2016

    I have some doubt.
    Raghus Says: Delegate is type which holds the method(s) reference in an object.
    My question is if Delegate is type then how we create a object of delegate? Because, we know that we can create object only struct and class.


    How do you make a class not instantiable

    A) Making class as AbstractB) Having a Private constructorC) Making the class sealedD) Both A & B

    Naveen Kumar Shivanadri

    • Sep 8th, 2016

    Answer is A is always correct and B is also correct only the situation when the class does not have the static methods on it (in the question, there is no mentioned that there is no static method in it)
    So, only A is correct answer.

    Naveen Kumar Shivanadr.


    • Oct 13th, 2015

    Making class as Abstract


    What is the difference between an interface and abstract class?

    In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

    Naveen Kumar Shivanadri

    • Sep 8th, 2016

    The basic difference is Abstract class can contain abstract methods (a method without method body) as well as concrete methods (a method with method body). Where as in the interface there is only f...

    Ramprit Sahani

    • Sep 1st, 2016

    Interface is an abstract class which has only public abstract methods and the methods only have the declaration and not the definition. These abstract methods must be implemented in the inherited clas...

Showing Questions 1 - 20 of 529 Questions
First | Prev | Next | Last Page
Sort by: 
Jump to Page: