Search This Blog

Friday 5 September 2014

Interview Questions for 5+ years Experience in dotnet

Interview Questions for 5+ years Experience in dotnet

1.Tell about your last project you worked on?
Answer:
Tell about the recent project you have worked on. The technology and the database you have worked on. Your roles and responsibilities.

2.When was the last time you did coding?

3.What is an assembly?
Answer:
PreCompiled code that can be executed by the .NET runtime environment. It can be an .exe or .dll

4.What are different kind of assemblies? What is satellite assembly and public assembly?
Answer:
There are three types of assemblies:
a.Public Assembly:dll which can be used by multiple applications at a time. It is generally stored in GAC(Global Assembly Cache). 
b.Private Assembly:It is used by only one application and generally stored in the Application specific folder.
c.Satellite Assembly:A Satellite Assembly contains only static objects such as images and other non-executable files such as resource-only files that are required by the application.

5.Can we have 2 assemblies with the same name in GAC?
Answer:
Yes we can have 2 assemblies with the same name in GAC as long as they have different strong names. The strong names of the assemblies can differ in name/version/culture/processor architecture/public key token.

6.What is the prerequisite to deploy an assembly in GAC?
Answer:
The assembly must be strong named. A 'strongly named' assembly is an assembly that is signed with a key to ensure its uniqueness

7.What is Strong Name?
Answer:
A strong name is a combination of its name, version number, and culture information (if provided) and a public key and a digital signature. This ensures that the Dll is unique.
•Strong names provides an integrity check that ensures that the contents of the assembly have not been changed since it was built.

8.What are indexers?
Answer:
Indexers are used for treating an object as an array. 
For more info refer:
http://www.dotnetspider.com/forum/160680-indexes-.NET.aspx 

9.What is the difference between abstract classes and interfaces?
Answer:
Interface must have only methods without implementation whereas abstract classes can have methods with and without implementation that is you can define a behavior in an abstract class. An interface cannot contain access modifiers whereas an abstract class can contain access modifiers. A class can implement multiple interfaces whereas a class can inherit only one abstract class. An interface cannot have variables whereas an abstract class can have variables and constants defined. When we add a new method to an interface, We have to track all the classes which implement this interface and add the functionality to this method whereas in case of abstract class we can add default behavior for the newly added method and thus the class which inherit this class works properly.

10.Have you worked on Threading?
Answer:
I did not get a chance to work on threading but I have knowledge about the threading concepts.

11.What are generics? how do you increase performance using generics?
Answer:
Generics allows you to define type-safe data structures, without specifying the actual data types. This increases the performance of the code and code resuse. Thus generics allows you to write a class or method that can work with any data type. Since Generics is type safe it avoids boxing and unboxing which increases the performance of the code because you need not convert an object to a specific datatype and viceversa.

12.How do you compare two dictionary objects?
Answer:
You can use the SequenceEqual method of the dictionary object to compare 2 dictionaries as shown below:
bool result = dic1.SequenceEqual(dic2);
Here result will be true if the two dictionary objects are equal else false.

13.Have you heard about IComparable? How does it work?
Answer:
A Class can implement IComparable interface if you want to compare the objects of that class. then in that class we have to implement the CompareTo method and provide the implementation to compare two class objects.
For more info refer:
http://www.dotnetspider.com/resources/42949-sorting-user-defined-collection-c-using.aspx

14.What is the difference between ref and out keyword. Is out a Reference variable?
Answer:
ref is initialized before entering the function which is called, whereas out variable is initialized inside the function. The out keyword used for a variable causes it to be passed by reference. It is used when a method has to return multiple values(one using return statement other using out keyword).

15.What is Managed code?
Answer:
Managed code is the code whose execution is managed by the .NET Framework Common Language Runtime(CLR). The CLR ensures managed execution environment that ensures type safety, exception handling,garbage collection and array bound & index checking.

16.What is UnManaged Code?
Answer:
Applications that do not run under the control of the CLR are said to be unmanaged. this is the code that is directly executed by the operating system.

17.How Unmanaged code is taken care by .Net Framework?
Answer:
In unmanaged code the memory allocation, type safety, security and other things have to be taken care by the developer. This can lead to memory leaks and buffer overrun.

18.What is Dispose and Finalize?
Answer:
The Dispose method is generally called by the code that created your class so that we can clean up and release any resources we have acquired ( database connections/file handles) once the code is done with the object. The finalize method is called when the object is garbage collected and its not guaranteed when this will happen.

19.ASP.NET Page Lifecyle events?
Answer:
Page_PreInit,Page_Init,LoadViewState(If it is a Postback),LoadPostBackData(If it is a Postback),Page_Load,Control event handler execution,Page_PreRender,SaveViewState,Page_Render,Page_Unload

20.In an ASP.NET page if you have a DropdownList and whenever you select some option in the dropdown list? It makes a post back to server. How can you increase the performance of this page?
Answer:
put the dropdownlist inside an AJAX UpdatePanel so it updates only that part of the page instead of a full page reload or we can also use AJAX webservice.

21.Have you used Caching in asp.net?
Answer:
Yes

22.What are difference Session Management Techniques in ASP.NET
Answer:
Sessions,Cookies,QueryString,ViewState,Application objects,Hidden Fields.

23.Difference between Internal and Protected access modifiers.
Answer:
A protected type or member can be accessed by code in the same class or in a derived class wheareas An internal type or member can be accessed by code in the same assembly.


24.Difference between ReadOnly and Const.
Answer:
A Const can be initialized only once whereas ReadOnly can be initialized at runtime in the constructor.
•Constants are static by default that is they are compile time constants
whereas Readonly are runtime constants.
•Constants must have a value at compilation-time and they are copied into every assembly that uses them.
Readonly instance fields must be set before the constructor exits because they are evaluated when object is created.

Web Services Questions:
since I had experience in Web Service. They asked below questions in webservice?

1.How do you mark a service method as webservice method?
Answer:
Decorate the method with the WebMethod attribute as shown below:
[System.Web.Services.WebMethod()]
public string GetData(string message)
{
return "My Service";
}

2.In a Web service If you have multiple methods and you have to make only one method as Web service method How can you do it?

Exception Handling in SQL Server Stored Procedure with TRY CATCH

BEGIN TRY
---Write Your Code
END TRY
BEGIN CATCH
---Write Code to handle errors
END CATCH


In TRY block we will write our queries and in CATCH block we will write code to handle exceptions. In our SQL statements if any error occurs automatically it will move to CATCH block in that we can handle error messages. To handle error messages we have defined Error Functions in CATCH block those are

ERROR_LINE() - This function will return error line number of SQL query which cause to raise error.

ERROR_NUMBER() - This function will return error number which is unique and assigned to it.

ERROR_SEVERITY() - This function will return severity of error which indicates how serious the error is. The values are between 1 and 25.

ERROR_STATE() - This function will return state number of error message which cause to raise error.

ERROR_PROCEDURE() - This function will return name of the procedure where an error occurred.

ERROR_MESSAGE() - This function will return the complete text of the error message which cause to raise error.

Check below sample query to handle errors in stored procedure

BEGIN TRY
SELECT 300/0
END TRY
BEGIN CATCH
SELECT ErrorNumber = ERROR_NUMBER(), ErrorSeverity = ERROR_SEVERITY(),
ErrorState =ERROR_STATE(),
ErrorProcedure = ERROR_PROCEDURE(), ErrorLine = ERROR_LINE(),
ErrorMessage = ERROR_MESSAGE()
END CATCH

If we run above query we will get output like as shown below
Output

Thursday 4 September 2014

OOPS Concepts

Class:
A class is a blueprint of an object that contains variables for storing data and
functions to perform operations on the data.
It is a collection of objects.
A class will not occupy any memory space and hence it is only a logical
representation of data
Object:
It is a real time entity.
An object is an instance of a class.
An object can be considered a “thing” that can perform a set of related activities.
What is encapsulation?
Encapsulation is the process of hiding irrelevant data from the user. To understand
encapsulation, consider an example of mobile phone. Whenever you buy a mobile,
you don’t see how circuit board works. You are also not interested to know how
digital signal converts into analog signal and vice versa. These are the irrelevant
information for the mobile user, that’s why it is encapsulated inside a cabinet.
In C# programming, we will do same thing. We will create a cabinet and keep all the irrelevant
information in it that will be unavailable for the user.
What is abstraction?
Abstraction is just opposite of Encapsulation. Abstraction is mechanism to show
only relevant
data to the user. Consider the same mobile example again. Whenever you buy a
mobile phone,
you see their different types of functionalities as camera, mp3 player, calling
function,
recording function, multimedia etc. It is abstraction, because you are seeing only
relevant
information instead of their internal engineering.
Encapsulation and Abstraction
Encapsulation and abstraction is the advanced mechanism in C# that lets your
program to
hide unwanted code within a capsule and shows only essential features of an object.
Encapsulation is used to hide its members from outside class or interface, whereas
abstraction
is used to show only essential features.
In C# programming, Encapsulation uses five types of modifier to encapsulate data.
These modifiers are public, private, internal, protected and protected internal.
Acquiring  or inherit the properties of one class (Base Class )to another class(Derived Class).
This also provides an opportunity to reuse the code functionality and fast implementation time.
Inheritance can be classified to 5 types.
1 Single Inheritance
2 Hierarchical Inheritance
3 Multi Level Inheritance
4 Hybrid Inheritance
5 Multiple Inheritance
1. Single Inheritance
when a single derived class is created from a single  base class then the inheritance is called as single inheritance.
2. Hierarchical Inheritance

when more than one derived class are created from a single base class, then that
inheritance is called as hierarchical inheritance.
3. Multi Level Inheritance

when a derived class is created from another derived class, then that inheritance is
called as multi level inheritance.
4. Hybrid Inheritance

Any combination of single, hierarchical and multi level inheritances is called as
hybrid inheritance.
5. Multiple Inheritance

when a derived class is created from more than one base class then that inheritance is
called as multiple inheritance. But multiple inheritance is not supported by
.net using classes and can be done using interfaces.
Handling the complexity that causes due to multiple inheritance is very 
complex. Hence it is not supported in dotnet with class and it can be 
achieved with interfaces.
Polymorphism
Polymorphism means many forms (ability to take more than one form). In
Polymorphism poly means “multiple” and morph means “forms”
so polymorphism means  many forms.
In polymorphism we will declare methods with same name and different
parameters in same class or methods with same name and same parameters in
different classes. Polymorphism has ability to provide different implementation
of methods that are  implemented with same name.
In Polymorphism we have 2 different types those are
  1.  Overloading 
Called as Early Binding or Compile Time Polymorphism or static binding
In a class  we will declare two or more  methods with same name but with different parameters
because of this we will perform different tasks with same method name.
Two Types
  1. Method Overloading
This can be achieved by :
Passing different number of parameters.
Passing different order of parameters.
Passing different types of parameters.
  1. Operator Overloading
  2. Method Overriding
Called as Late Binding or Run Time Polymorphism or dynamic binding
In this run time polymorphism or method overriding we can override a method in base class
by creating similar function in derived class this can be achieved by using inheritance
principle and using “virtual &override” keywords.
In base class if we declare methods with virtual keyword then only we can override those
methods in derived class using override keyword
Types of classes
  • Abstract Class (somtimes called a Pure Virtual Class)
An Abstract Class means that, no object of this class can be instantiated, but can make
derivation of this. It can serve the purpose of base class only as no object of this class can
be created.
Abstract Class is denoted by the keyword abstract.
  • Partial Class
This special type of class called “Partial Class” is introduced with .Net Framework 2.0. Partial
Class allows its members – method, properties, and events –
to be divided into multiple source files (.cs). At compile time these files
get combined into a single class.
Partial Class is denoted by the keyword partial.
Some do’s and don’ts about partial class:-
• All the parts of a partial class must be prefixed with the keyword partial.
• Accessibility, signature etc. must be same in all parts of the partial class.
• You cannot sealed one part of the partial class. In that case entire class in sealed.
• If you define any part of the partial class abstract, entire class will become abstract.
• Inheritance cannot be applied to a part of partial class. If you do so, it applies to entire
class.
  • Sealed Class
A sealed class is a class which cannot be inherited. A sealed class cannot be a base class.
The modifier abstract cannot be applied to a sealed class. It is the last class in hierarchy.
To access the members of a sealed class, you must create objects of that class.
Sealed Class is denoted by the keyword sealed.
  • Static Class
A Static Class is one which cannot be instantiated. The keyword new cannot be used
with static classes as members of such class can be called directly by using the class
name itself.
Following are the main characteristics of a static class:-
• A Static Class can only have static members.
• A Static Class cannot be instantiated.
• A Static Class is sealed, so cannot be inherited.
• A Static Class cannot have a constructor (except static constructor).
Static Class is denoted by the keyword static.