Monday 30 January 2017

C# basic interview questions Part-2

1. Ques: What is an interface in c#  and what are the advantages of interface ?
Answer:
An interface  is a type  which contains only the signatures of methods, properties, events or indexers.it has no implementation.The class contract with Interface has resposible for Implementation of the signatures of methods, properties.
  • An Interface is a reference type.
  • It does not Contains any data members.
  • No access modifier apply in interface.
  • By Default interface members is public. 
  • It Supports multiple interfaces.
Advantages of  an interface
  • Only Multiple interface supported in C#.but Multiple inheritance not supported.
  • For creating loosely coupled module.
  • Allow different objects to interact easily.
  • Extensibility.
  • Interface help for Dependency injection and inversion of control

2. Ques: What is Garbage Collection ?
Answer:
  • Garbage Collector is part of CLR in .Net Framework which is responsible to Automatic Memory Management.
  • It is collect all unused memory area and give to application to realeae the memory.
  • Garbage Collector use a system.gc.collect() method for release the memory.
  • Garbage Collector dived the heap memory into three Generation Generation 0, Generation  1, Generation 2.
  • It check the object which is short live or long live and put that object into Generation 0,1,2 respectvley.
  • garbage collector does not clean unmanaged objects it clean only managed objects.
Generation 0 (Zero): short-lived objects store in this Generation, e.g., Temporary objects. GC initiates garbage collection process frequently in this generation.
Generation 1 (One): This generation is the buffer between short-lived and long-lived objects.
Generation 2 (Two): This generation holds long-lived objects like a static and global variable.

Garbage collection happend when any one of the following conditions is true:
The system has low physical memory.
The GC.Collect method is called.


3. Ques: What is CLR ?
Answer:
Common Language Runtime (CLR) is the heart of the dot Net framework. it provides run time environment to run all the dot Net Programs. it execute MSIL (Microsoft Intermediate Language) code to native code. The code which runs under the CLR is called as Managed Code.

CLR  provides a common set of services in dot Net framework
Memory management (using Garbage Collector): it relesed unuesed obect from heap memory.
Exception handling and errors: It is allows create code and handle the exceptions.
Security managment : CLR provide Code Access Security (CAS) which restrict to run unauthorized code.
Thread management: Allows to run multiple threads of execution.
JIT compiler: JIT is part of CLR which convert MSIL code into native code.
Type loading:  Finds and loads assemblies and types.
Type safety:  It Ensures the references match compatible types.
Code Manager:  It manages the code at run time.
Class Loader: Used to load all classes at run time.


4. Ques: What is the CLS (Common Language Specification)?
Answer:
Common Language Specification and it is a subset of CTS. It defines a set of rules and restrictions that every language must follow which runs under .NET framework. CLS enables cross-language integration. CLS represents the guidelines to the compiler of a language, which targets the .NET Framework.


5. Ques: What is the CTS ?
Answer:  
Common Type System (CTS) defines a set of types that can use different dot Net languages, and after compilation of different  dot Net languages it treated as single type. It enables cross-language integration, type safety, and high-performance code execution. It provides an object-oriented model for implementation of many programming languages.


6. Ques: What is difference between dispose and finalize method in c# ?
Answer:  
Dispose
it is used to free unmanaged resources like files, database connections, unmanaged memory etc. at any time.
it is called by User Code. So we can say that it called Explicitly.
Dispose() method belongs to IDisposable interface.
Performance of application not affected with Dispose method.

finalize 
it is used to free unmanaged resources like files, database connections, unmanaged memory etc etc. before object is destroyed.
it is called by Garbage Collector. so we can say that it called Internally.
finalize() method belongs to object class.
Performance of application is affected with finalize method.


7. Ques: What is GAC ? What are the steps to create an assembly and add it to the GAC ?
Answer:
The global assembly cache (GAC) is a Directory that stores assemblies that is shared by several applications on the computer. You should share assemblies by installing them into the global assembly cache.

Steps for installing
  • Create a strong name using sn.exe tool eg: sn -k mykey.snk
  • in AssemblyInfo.cs, add the strong name eg: [assembly: AssemblyKeyFile("mykey.snk")]
  • recompile project, and then install it to GAC in two ways :
  • drag & drop it to assembly folder (C:\WINDOWS\assembly OR C:\WINNT\assembly) (shfusion.dll tool)
  •  gacutil -i abc.dll

8. Ques: What is a strong name?
Answer:
You need to assign a strong name to an assembly to place it in the GAC and make it globally accessible. A strong name consists of a name that consists of an assembly's identity (text name, version number, and culture information), a public key and a digital signature generated over the assembly.  The .NET Framework provides a tool called the Strong Name Tool (Sn.exe), which allows verification and key pair and signature generation.


9. Ques: Is it possible to force garbage collector to run?
Answer:
Yes, we can force garbage collector to run using System.GC.Collect().
It can be used to avoid calling any of the collect methods and allow the garbage collector to run independently.
It is better at determining the best time to perform a collection.

Sunday 29 January 2017

MVC interview questions Part 1

Ques: Explain MVC architecture?
Answer: 
The Model-View-Controller (MVC) is an architectural pattern that separates an application into three main logical components

Model: Model is a set of classes that describe the business logic for the application data.
View  : View is UI components which  display of the data on browser.
Controller : Controllers responsible to process incoming requests.it manuplate logic with modal and bind data modal with view.


Ques: Explain ASP.NET MVC Pipeline Request Life Cycle?
                         or
          Explain Request Life Cycle of ASP.NET MVC ?
Answer:
Here the diagram show the sequence of Request Life Cycle of ASP.NET MVC.


Request come from IIS enter into url routing module. The routing table find out which
controler action method map to incoming URL pattern. Now in Routing module  there is MVC routeHandler which bring the request to MVC HttpHandler. Now MVC HttpHandler start intilizing of Controler and excute it. The MVCHttpHandler has IControllerFactory factory which responsible for excute instnce of controler. Once the controller has been instantiated, Controller's ActionInvoker determines which specific action to invoke on the controller.once Action method has been finished executing the next step is Result execution.If the result is a view type, the View Engine will be called and it's responsible for finding and rending our view.


Ques:  What are advantages of ASP.NET MVC framework ? 
Answer:
The following lists are the asp.net page life-cycle events.

 Separation of Concerns :It is core advantages MVC framework.The framework divides into three main part Model, View and Controller which make it easier to manage the application complexity.

 Lightweight framework: ASP.NET MVC framework doesn’t View State and thus reduces the bandwidth of the requests to an extent.

Test-driven development : The MVC framework brings better support to test-driven development.Unit Test can done very esaly.

Easy Extensible and pluggable: ASP.NET MVC framework easly customized with diffrent pluggin & Extensible after development over.

Search Engine Optimization (SEO) Friendly : URL's are more friendly for search engines because of URL routing mechanism.

ASP.NET features are supported:  MVC is built on top of ASP.NET so all of the features that ASP.NET include in this framework.

Less change Requirement Time : Developer can do change Requirement very frequently in very less time.

Ques: List out few different return types of a controller action method ?
Answer: 
View Result
Javascript Result
EmptyResult
PartialViewResult
JavaScriptResult
RedirectToRouteResult
Redirect Result
Json Result
Content Result
FileContentResult
FileStreamResult
FilePathResult


Ques: What are the difference between ViewData, ViewBag, Temp data and Session?
Answer: 

ViewData-
  • ViewData is used to pass data from controller to view.
  • It is available for the current request only.
  • ViewData is a dictionary which is derived from ViewDataDictionary class.
  • ViewData requires typecasting for complex data type and check null values to avoid error.
  • If redirection occurs, then its value becomes null.
  • It maintain data when request move from controller to view.
  • ViewData is Faster than ViewBag
  • ViewData is introduced in MVC 1.0
ViewBag-
  • ViewBag is also used to pass data from controller to view.
  • ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0
  • It is also available for the current request only.
  • If redirection occurs, then its value becomes null.
  • ViewBag doesn’t require typecasting for complex data type.
  • ViewBag is slower than ViewData.
  • ViewBag is introduced in MVC 3.0
TempData-
  • TempData is a dictionary object and it is property of controllerBase class.
  • TempData is used to pass data from one controler to another controler.
  • TempData is only work during the current and subsequent request.
  • TempData is derived from TempDataDictionary class.
  • It requires typecasting for complex data type and checks for null values to avoid error. 
  • It helps to maintain the data when we move from one controller to another controller or from one action to another action
  • TempData introduced in MVC1.0 
Session -
  • Session data mentain for all request until session timeout not expired.
  • Session is valid for all requests, not for a single redirect.
  • It requires typecasting for type and checks for null values to avoid error.
  • Session data are stored in SessionStateItemCollection object.



ASP.NET interview questions Part-1

1. Ques: Brief about ASP.NET Page Life Cycle ?
Answer: 
Page request
Page Start
Page Initialization
Page Load
Postback event handling
Page Rendering
Page Unload


2. Ques: Brief about ASP.NET Page Life Cycle event ?
Answer: 
The following lists are the asp.net page life-cycle events.
1.PreInit event
2.Init event
3.InitComplete event
4.PreLoad event
5.Load event
6.LoadComplete
7.PreRender event
8.PreRenderComplete event
9.SaveStateComplete event
10 Render event
11.Unload event

PreInit:  PreInit is the first event in asp.net page life cycle.
               it set a master page dynamically.
               it set the theme property dynamically.
               it create or re-create dynamic controls.
               IsCallback and IsCrossPagePostBack properties have also been set in this event.
               Read or set profile property values.

Init: This event called when you can initialize your page controls property.

InitComplete: This event Raised at the end of the page's initialization stage. InitComplete event allows tracking of view state.

PreLoad: This event viewstate starts retrieving their values from controls.

Load: This Load event is raised for the page first and then recursively for all child controls.

Control: This events raised  to handle specific control events, such as a Button control's Click event.

LoadComplete: This events raised after loading process is completed.

PreRender: This events raised just before the output is rendered.

PreRenderComplete: This events raised after output is completed.

SaveStateComplete: This events saved the view state information.

Render: This is not an event; instead, at this stage of processing HTML of your page writes out the control's markup to send to the browser.

Unload: This events is last event that gets fired in Page Life Cycle .this event use for cleaning process like closing the open file connections etc..


3. Ques :  What is State Management in ASP.NET.? How many are State Managements and explain them.
Answer: 
State management is the process that maintain state of control and page over multiple requests for the same or different pages.

There are two types of state management techniques  in ASP.Net
Client side state management
  • Hidden Field
  • View State
  • Cookies    
  • Query Strings
Server side state management
  • Session 
  • Application
Client side state management

Hidden Field: 
 Hidden Fields are small amounts of data on the client side.
 It does not get displayed on the UI(browser).
 It Contains a small amount of memory.
 No server resource required.

View State: 
View State use preserve page and control values between round trips.
 It is Page-Level State Management technique .when request go from one page to other page                View State data lost.
 It Can store any type of data.
 View State use for to track the values in the Controls in asp.net.

Cookies: 
A small text file that is stored in the user's browser.
If new session created then A new cookie will be generated and store your browser until you           close your browser.
Generally cookie is used to identify users.and it Store information temporarily.
Cookies are not good for storing sensitive data.
       
 Two type of Cookie
Persist Cookie - A cookie has not have expired time Which is called as Persist Cookie.it                    exist on hard drive until you erase them or they expire
(Session cookies) Non-Persist Cookie - These cookies are saved in memory and will be lost               while closing your browser.
A new session cookie will be generated, which will store your browsing information and will             be active until you leave the site and close your browser.

Query Strings:
Query String sent information to the server by URL that are visible to the user.
It is way to transfer information from one page to another through the URL.
It store the value in the form of Key-Value pair.

Server side state management 
Session:Session state stores user specific information and the information is visible within that session only. sessions are stored in server memory called as In-Process.and sessions are stored out server memory called out- Proc.Session object store any type of data.

Application: The data stored in an application object can be Access by all user of the application.
The application object stores data in the key value pair.Data stored in the application object should be of small size.


5. Ques :What are the different types of sessions in ASP.Net? Explain them.
Answer: 
Session Management can be achieved in two ways

1) InProc
2) OutProc

OutProc is again two types
a)State Server
b)SQL Server

InProc: It stores state in Web server memory. This is the default sessions sate.
Advantages:
1) Faster as session resides in the same process as the application
2) No need to serialize the data

 Dis Advantages:
1) Will degrade the performance of the application if large chunk of data is stored
2) On restart of IIS all the Session info will be lost


State Serve: Stores session state in a separate process called the  state service.
Advantages:
1) Faster then SQL Server session management
2) Safer then InProc. As IIS restart session data not lost.
3) won't effect the session data

Dis Advantages.:
1) Data need to be serialized
2) On restart of ASP.NET State Service session info will be lost
3) Slower as compared to InProc.

SQL Server: Session state store in a SQL Server database.
Advantages
1) Reliable and Durable.
2) IIS and ASP.NET State Service restart won't effect the session data
3) Good place for storing large chunk of data

Dis Advantages:
1) Data need to be serialized
2) Slower as compare to InProc and State Server
3) Need to purchase Licensed version of SQL Serve


6. Ques : What is the difference between GET method() and POST method()?
Answer
GET method( )

  • Data is affixed to the URL.
  • Data is not secured.
  • Data transmission is faster in this
  • This is a single call system.
  • Only limited amount of data can
  • be sent.
  • It is a default method for many
  • browsers.

POST method( )

  • Data is not affixed to the URL.
  • Data is secured.
  • Data transmission is comparatively slow.
  • This is a two call system
  • Large amount of data can be sent.
  • It is not set as default. it should be explicitly specified.

C# basic interview questions Part-1

1. Ques: What are the version numbers of C# ? 
Answer:


Version
.NET Framework
C# 1.0
.NET Framework 1.0/1.1
C# 2.0
.NET Framework 2.0
C# 3.0
.NET Framework 3.0\3.5
C# 4.0
.NET Framework 4.0
C# 5.0
.NET Framework 4.5
C# 6.0
.NET Framework 4.6


2. Ques: What is difference between Dictionary & Hashtable ?
Answer:
Dictionary:
1.Dictionary is generic type.
2.Returns an error if the key does not exist.
3.No boxing and unboxing.
4.Faster than a Hash table.
5.dictionary is not tread safe.

Hashtable:
1.Hashtable is not generic type.
2.Returns NULL even if the key does not exist.
3.Requires boxing and unboxing.
4.Slower than a Dictionary.
5.hash table is not a generic type.
6.hash table is tread safe.


3. Ques: What is Reflection in dot net? 
Answer:
  • Reflection used for obtaining type information of assembly at runtime. 
  • It Load assemblies at runtime and give the information of field,properties, constructors, event and methods of class.
  • It is a collection of classes which allow u to query assembly (class/object) metadata at runtime.
  • Using reflection we can also create new types and their instances at runtime and invoke methods on these new instances.
  • At runtime, the Reflection mechanism uses the PE file to read information about the assembly.
  • We can dynamically invoke methods using System.Type.Invokemember
  • We can dynamically create types at runtime using System.Reflection.Emit.TypeBuilder
  • Reflection objects are used for obtaining type information at runtime. 
  • The classes belong to the System.Reflection namespace.
With reflection we can do the below task

  • we can dynamically create an instance of a type
  • bind the type to an existing object
  • get the type from an existing object
  • invoke its methods or access its fields and properties



4. Ques: What are Assemblies?
Answer:
Assembly is the smallest unit of deployment of a .net application. 
It can be either dll or an exe.

5. Ques: How many type of assembly are in .net framework?
Answer:
There are three type of assembly in .net framework?
Private: It is stored in the application's directory. 
Shared : It is stored in GAC (Global Assembly Cache).
Satelite : It is stored in specific application's directory.


6. Ques: What is array?
Answer:
  • Array as a collection of variables of the same type of fixed-size. 
  • Array are reference types.
  • array strongly type of collection.
  • arrays belong to "System.Array" namespace

ex:  int[] arr = new int[10];
       string[] arr = new string[10];
       bool[] arr = new bool[2];



7. Ques:What are different type of array in c#?
Answer : Three types  of array in C#:
Single Dimensional Array: It contains a single row. It is also known as vector array.
Multi Dimensional Array: It is rectangular and contains rows and columns.
Jagged Array: In Jagged Array the element is itself is array. It also contains rows and columns but it has an irregular shape.


8. Ques: How to create jagged arrays in c#?
Answer :
int[][] jagrray= new int[4][];
jagrray [0] = new int[5];
jagrray[1] = new int[3];
jagrray[2] = new int[2];
jagrray[3] = new int[1];

for (int i = 0; i < jagrray.Length; i++)
    {
        int[] innerArray = jagrray[i];
        for (int j = 0; j < innerArray.Length; j++)
        {
            Console.Write(innerArray[j] + " ");
        }
        Console.WriteLine();
    }


9. Ques: What is Arraylist?
Answer:
  • Arraylist collection of variables of same or different datatypes. 
  • Arraylist class found in "System.Collections” namespace.
  • Size of arraylist object will increase or decrease dynamically.
  • Arraylist very flexible because we can add & delete without any size information.
  • Arraylist not a strongly type of collection. 

10. Ques: What is a collection.how many types of collection in C#?
Answer:
Collections are data structures that holds data or objects in memory.
list of collection which supported by C# given bellow.
ArrayList
HashTable
SortedList
BitArray
Queue
Stack




Friday 6 January 2017

Oops concept questions Part-1

Ques: What is object in c# ?
An object is an instance of a class. The new operator is used to create an object of a class. When an object of a class is instantiated, the system allocates memory for every data member of that class.

Ques: What is class ?
Class is a template or blueprint that is used for creating an object.
Class is reference type.

Ques: What are the different type of class in c# ?
There are four types of classes in C# .Net
1. Abstract class
2. Sealed class
3. Static class
4. Partial class

1) Abstract class - An Abstract Class means that, we can not create instance of this class, but can create instance of derivation of this class.Abstract class always act as base class. for creating Abstract Class the abstract keyword use.

2) 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. By default, struct (structure) is sealed.Sealed Class is denoted by the keyword sealed.

3) Static class - A Static Class is one which cannot be instantiated. The keyword new cannot be used with static classes.

4) Partial class - Partial Class allows its members – method, properties, and events – to be divided into multiple source files. At compile time these files get combined into a single class.

Ques: What are the main OOP’s concepts ?
Abstraction, Encapsulation, Inheritance and Polymorphism are the main OOP’s concepts.

Ques: What is Encapsulation ?
Encapsulation is way to hide data, properties and methods from outside the class scope.
for Encapsulation private modifier keyword usually used.

Ques: How we can implement Encapsulation in class ?
by using "private" access access modifier
ex:
public Class Car
          {
                private enginstype="";
                private void CalculateSpeed(){
                Console.WriteLine("speed of car 300 m/h");
          }
}

Ques: What is Abstraction ?
Abstraction is a mechanism which represent the essential features without including implementation details.Abstraction Showing Whats Necessary to client

Ques: What is Polymorphism ?
Polymorphism means having more than one form.it is one of the most important future of object-oriented programming
                                                   or
Polymorphism is the ability of objects of different types to provide interface for implementations of methods.

Ques: What are different types of polymorphism in C#
There are two type of polymorphism
1. Compile time Polymorphism or Early Binding (Method Overloading)
2. Runtime Polymorphism or Late Binding (Method Overriding)


Ques: What is Inheritance ?
 Inheritance provide you to create new classes (child class) that reuse, extend, and modify the behavior that is defined in other classes (Parent class).

Ques: What is Constructor ?
A constructor is an instance method which is the same name as the class.
                                                   or
Constructor is a method which executed automatically when we instant object of that class.
it used to initialize the filed of class before using of  an object.
  • A class can have many number of constructors.
  • A constructor doesn't have any return type.
  • A constructor can be called another constructor by using "this" keyword.

Ques: What are type of Constructor ?
Default Constructor: In default constructor does not have any input parameter.
Parametrized Constructor:In parameterized constructor having one or more parameters.
Static Constructor: It invoked only during the first initialization of instance. It is used to initialize static fields of the class
Private Constructor:A class with private constructor cannot be inherited.
Copy Constructor:A constructor that contains a parameter of same class type is called as copy constructor.

Ques: Define Destructor ?
Answer:
Destructor is a method which is automatically called when the object is destroyed.
Destructor name is also same as class name but with the tilde symbol before the name.


Ques: What is the difference between a class and a structure ?
Answer:
Class:
A class is a reference type.
While instantiating a class, its instance allocated on heap memory .
Classes support inheritance.
Variables of a class can be assigned as null.
Class object cannot be created without using the new keyword.
Class  can be abstract.
Classes are usually used for large amounts of data.

Structure:
A structure is a value type.
In structure, memory is allocated on stack.
Structures does not support inheritance.
Structure members cannot have null values.
Structure object can be created without using the new keyword.
A structure can't be abstract.
structure are usually used for smaller amounts of data.


Ques: What is namespace ?
A namespace provides a fundamental unit of logical code grouping.

Ques: What is Sealed class ?
Answer: A sealed class is a class that does not allow inheritance.
Some object model designs need to allow the creation of new instances but not inheritance, if this is the case, the class should be declared as sealed.