RSS

C# – Interview Questions (Part-02)

21 Aug

job-interview

So you want to land your dream job as a C# programmer? You will need to prove that you know your stuff before any organization will hire you. Here are ten of the most common interview questions that interviewers will use to test your technical knowledge and problem solving skills. Can you answer them all?

01. What is the difference between Array and Arraylist?  

In an array, we can have items of the same type only. The size of the array is fixed. An arraylist is similar to an array but it doesn’t have a fixed size.

02. Can a private virtual method be overridden?  

No, because they are not accessible outside the class.

03. Describe the accessibility modifier “protected internal”.

Protected Internal variables/methods are accessible within the same assembly and also from the classes that are derived from this parent class.

04. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

Using Clone() method, we creates a new array object containing all the elements in the original array and using CopyTo() method, all the elements of existing array copies into another existing array. Both the methods perform a shallow copy.

05. What’s the difference between an interface and abstract class?

Briefly: Interfaces have all the methods having only declaration but no definition. In an abstract class, we can have some concrete methods. In an interface class, all the methods are public. An abstract class may have private methods.

In details .. click here

In points:

Abstract Class:

  • Abstract class provides a set of rules to implement next class
  • Rules will be provided through abstract methods
  • Abstract method does not contain any definition
  • While inheriting abstract class all abstract methods must be override
  • If a class contains at least one abstract method then it must be declared as an “Abstract Class”
  • Abstract classes cannot be instantiated (i.e. we cannot create objects), but a reference can be created
  • Reference depends on child class object’s memory
  • Abstract classes are also called as “Partial abstract classes”
  • Partial abstract class may contain functions with body and functions without body
  • If a class contains all functions without body then it is called as “Fully Abstract Class” (Interface)

Interface:

  • If a class contains all abstract methods then that class is known as “Interface”
  • Interfaces support like multiple inheritance
  • In interface all methods r public abstract by default
  • Interfaces are implementable
  • Interfaces can be instantiated, but a reference cannot be created

06. What is the difference between Finalize() and Dispose() methods?

Dispose() is called when we want for an object to release any unmanaged resources with them. On the other hand Finalize() is used for the same purpose but it doesn’t assure the garbage collection of an object.

07. What are generics in C#.NET?

Generics are used to make reusable code classes to decrease the code redundancy, increase type safety and performance. Using generics, we can create collection classes. To create generic collection, System.Collections.Generic namespace should be used instead of classes such as ArrayList in the System.Collections namespace. Generics promotes the usage of parameterized types.

08. What are delegates?

Delegates are same are function pointers in C++ but the only difference is that they are type safe unlike function pointers. Delegates are required because they can be used to write much more generic type safe functions.

09. What is the difference between method overriding and method overloading?

In method overriding, we change the method definition in the derived class that changes the method behavior. Method overloading is creating a method with the same name within the same class having different signatures.

10. Why can’t you specify the accessibility modifier for methods inside the interface?

In an interface, we have virtual methods that do not have method definition. All the methods are there to be overridden in the derived class. That’s why they all are public.

11. How can we set class to be inherited, but prevent the method from being over-ridden?

Declare the class as public and make the method sealed to prevent it from being overridden.

12. What happens if the inherited interfaces have conflicting method names?

Implement is up to you as the method is inside your own class. There might be problem when the methods from different interfaces expect different data, but as far as compiler cares you’re okay.

13. What is difference between is and as operators in c#?

  • “is” operator is used to check the compatibility of an object with a given type and it returns the result as Boolean.
  • “as” operator is used for casting of object to a type or a class.

14. What’s a multicast delegate?

A delegate having multiple handlers assigned to it is called multicast delegate. Each handler is assigned to a method.

15. What are circular references?

Circular reference is situation in which two or more resources are interdependent on each other causes the lock condition and make the resources unusable.

 
Leave a comment

Posted by on August 21, 2013 in Visual C# . NET

 

Tags: , , , , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: