Monday, May 18, 2015

ASP.NET Interview Questions and Answers

1.  ASP.Net Architecture?

ASP.NET has extended into multiple code frameworks, including Web Forms, MVC, Web Page, Web API and SignalR. Initially, all these grew up separately but now they are coming together. Now, you can develop your web site or web application by using Web Forms or MVC or Web Page and services by using Web API or SignalR.

Components of Asp.NET 4.5 Architecture

.NET Framework

.Net framework is an integrated component of windows operating system that supports development and execution of next generation applications, Windows store apps and services.

ASP.NET Framework

ASP.Net Framework is used to create dynamic website, web application and web services. It is built on the top of .NET Framework.

Asp.NET Framework provides you various capabilities like Hosting Model, Site/Service Management, Protocol Abstraction, Security, Caching capability, Routing and Model Binding etc.

Asp.NET Site

There are following flavours of Asp.NET Site -Web Forms

This is the traditional event driven development model. It has drag and drop server controls, server events and state management techniques. This best for rapid application development (RAD) with powerful data access.

MVC

This is a lightweight and MVC (Model, View, Controller) pattern based development model. It provides full control over mark-up and support many features that allow fast & agile development. This best for developing lightweight, interactive and device oriented (i.e. compatible to smart phones, iPhone, tablet, laptop etc.) web application with latest web standards.

Web Pages

This is also a lightweight and Razor syntax based development model. It has built-in template and helpers also provide full control over mark-up. It is best for developing beautiful web application with latest web standards. You can also use WebMatrix which is a free tool and has built-in template; for developing Asp.Net Web Page.

SPA

SPA stands for Single Page Application which helps you to build web applications that include significant client-side interactions using HTML5, CSS3 and JavaScript. It is best to make highly interactive single page dashboard web applications.

Asp.NET Services

There are two ways to make Asp.Net Services as given below –Web API

Asp.Net Web API is a framework for building HTTP services that can be consume by a broad range of clients including browsers, mobiles, iphone and tablets.

SignalR

ASP.NET SignalR is a library that simplifies the process of adding real-time web functionality to applications. Real-time web functionality is the ability to have server code push content to connected clients instantly as it becomes available, rather than having the server wait for a client to request new data.

Visual Studio 2012

The Visual Studio IDE offers a set of tools that help you to write and modify the code for your programs, and also detect and correct errors in your programs. Using Visual Studio 2012 you can build Windows Store apps, desktop apps, mobile apps, ASP.NET web apps, and web services.


2. ASP.Net Life Cycle? 


ASP.NET page passes through a series of steps during its life cycle. Following is the high-level explanation of life cycle stages/steps.

Initialization: Controls raise their Init event in this stage.Objects and variables are initializes for complete lifecyle of request.

LoadViewState: is a post back stage and loads the view state for the controls that enabled its view state property.

LoadPostBackData: is also a post back stage and loads the data posted for the controls and update them.

Load: In this stage page as well as all the controls raise their Load event. Till this stage all the controls are initialized and loaded. In most of the cases, we are coding this event handler.

RaisePostBackEvent: is again a postback stage. For example, it's raise against a button click event. We can easily put our code here to perform certain actions.

SaveViewState: Finally, controls state is saved in this stage before Rendering HTML.

Render: This is the stage where HTML is generated for the page.


Dispose: Lastly, all objects associated with the request are cleaned up.

    3. What is OOPs:

Introduction to Object Oriented Programming (OOP) concepts in C#: Abstraction, Encapsulation, Inheritance and Polymorphism.

OOP Features

Object Oriented Programming (OOP) is a programming model where programs are organized around objects and data rather than action and logic.

OOP allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects.

The software is divided into a number of small units called objects. The data and functions are built around these objects.
The data of the objects can be accessed only by the functions associated with that object.
The functions of one object can access the functions of another object.
OOP has the following important features.

Class

A class is basically a combination of a set of rules on which we will work in a specific program. It contains definitions of new data types like fields or variables, operations that we will perform on data (methods) and access rules for that data.

A class is a blueprint of an object that contains variables for storing data and functions to perform operations on the data.

A class will not occupy any memory space and hence it is only a logical representation of data.

Example

Class Example
{
    /* fields,
    Variables,
    Methods,
    Properties,
    */
}

To create a class, you simply use the keyword "class" followed by the class name:

Object

Objects are defined as an instance of a class. Objects are built on the model defined by the class. An object can be created in memory using the "new" keyword. In C# objects are reference types and other data type variables are value types. In C# objects are stored in the heap while other value types are stored in the stack.

Objects are the basic run-time entities of an object oriented system. They may represent a person, a place or any item that the program must handle.

"An object is a software bundle of related variable and methods."

"An object is an instance of a class"

A class will not occupy any memory space. Hence to work with the data represented by the class you must create a variable for the class that is called an object.

When an object is created using the new operator, memory is allocated for the class in the heap, the object is called an instance and its starting address will be stored in the object in stack memory.

When an object is created without the new operator, memory will not be allocated in the heap, in other words an instance will not be created and the object in the stack contains the value null.

When an object contains null, then it is not possible to access the members of the class using that object.


Example


Example exmplObject = new Example(); 

Inheritance

Inheritance is relevant due to the concept of “Code Reusability”. Inheritance is a feature by which a class acquires attributes of another class. The class that provides its attributes is known as the base class and the class that accepts those attributes is known as a derived class. It allows programmers to enhance their class without reconstructing it.

Example

class BaseClass
{
}
class DerivedClass : BaseClass
{
}


Now an object of a derived class can use the accessible properties of the base class without defining it in the derived class.

Encapsulation

Encapsulation is defined as hiding irrelevant data from the user. A class may contain much information that is not useful for an outside class or interface. The idea behind this concept is “Don’t tell me how you do it. Just do it.”.

So classes use encapsulation to hide its members that are not relevant for an outside class or interface. Encapsulation can be done using access specifiers.

Wrapping up a data member and a method together into a single unit (in other words class) is called Encapsulation.

Encapsulation is like enclosing in a capsule. That is enclosing the related operations and data related to an object into that object.


Encapsulation is like your bag in which you can keep your pen, book etcetera. It means this is the property of encapsulating members and functions.

class Bag
    {
        book;
        pen;
        ReadBook();
    }

Encapsulation means hiding the internal details of an object, in other words how an object does something.

Encapsulation prevents clients from seeing its inside view, where the behaviour of the abstraction is implemented.

Encapsulation is a technique used to protect the information in an object from another object.

Hide the data for security such as making the variables private, and expose the property to access the private data that will be public.

So, when you access the property you can validate the data and set it.

Abstraction

Abstraction is defined as showing only the relevant data to the user. Generally abstraction and encapsulation are explained in confusing manners.

Abstraction is "To represent the essential feature without representing the background details."

Abstraction lets you focus on what the object does instead of how it does it.

Abstraction provides you a generalized view of your classes or objects by providing relevant information.

Abstraction is the process of hiding the working style of an object, and showing the information of an object in an understandable manner.

Abstraction means putting all the variables and methods in a class that are necessary.
For example: Abstract class and abstract method.

Abstraction is a common thing.

Example

So just take an example of Mobile Phone Design.
Relevant Features of a phone in which the user is interested are Camera, Music player, Calling function, Voice recording and so on.

Irrelevant Features of a phone in which the user is not interested are circuit board design, hardware used and so on.

So in designing the Mobile Phone Model, both relevant and irrelevant features are required. But we need to show only relevant features. So we design a Mobile Phone in such a way that only relevant features are shown and irrelevant features are hidden. And remember one thing, that deciding relevant and irrelevant features is totally a user choice.

Polymorphism

Polymorphism is defined as the implementation of the same method with different attributes in a different context.

Example

For example, we have a class named shape with a method name buildshape(). We need to use it in the class Circle, class triangle and the class quadrilateral. So for every class we use the buildshape() method but with different attributes.

4. What is State Management?

Web is Stateless. It means a new instance of the web page class is re-created each time the page is posted to the server. As we all know HTTP is a stateless protocol, its can't holds the client information on page. As for example , if we enter a text and client on submit button, text does not appear after post back , only because of page is recreated on its round trip.


As given in above pages, page is recreated before its comes to clients and happened for each and every request. So it is a big issue to maintain the state of the page and information for a web application. That is the reason to start concept of State Management. To overcome this problem ASP.NET 2.0 Provides some features like View State, Cookies, Session, Application objects etc. to manage the state of page.

5. What is the type of Management?

There are two different types of state management:

1. Client Side State Management
  • View State
  • Hidden Field
  • Cookies
  • Control State

2. Server Side State Management
  • Session
  • Application Object
  • Caching
  • Database

Client Side state management does not use any server resource , it store information using client side option. Server Side state management use server side resource for store data. Selection of client side and server side state management should be based on your requirements and the selection criteria that are already given.

6. What is ViewState?

As in earlier question, we understood the concept of postback. So, in order to maintain the state between postbacks, ASP.NET provides a mechanism called view state. Hidden form fields are used to store the state of objects on client side and returned back to server in subsequent request (as postback occurs).

Where is view state stored?

View State stored the value of page controls as a string which is hashed and encoded in some hashing and encoding technology. It only contains information about page and its controls. Its does not have any interaction with server. It stays along with the page in the Client Browser. View State use Hidden field to store its information in a encoding format.

7. What is Postback?

Today, I am going to tell you about postback and cross page posting. Every developer who is working on ASP.NET has to do this thing in his project. This is an important part of the project and that is posting one page to another. Whenever you develop a website, you have a requirement to post to other pages. But ASP.NET pages postback to themselves in order to process events. For example, you have a data entry page and when you fill this page and click on submit button, then after saving the data, this page posts back to itself.

A postback is a request sent from a client to server from the same page user is already working with.
ASP.NET was introduced with a mechanism to post an HTTP POST request back to the same page. It's basically posting a complete page back to server (i.e. sending all of its data) on same page. So, the whole page is refreshed.

You will have to know the difference between postback for the first time when the new page is loaded and postback for the second time. So postback is just posting back to the same page. Remember one thing, the postback contains all the information collected on the Initial page for processing.

Now the question is this... how can you know whether the page is postback for the first time or not. The ASP.NET Page class has a property IsPostBack. You can check this using IsPostBack.

Here is the code for this:

Hide   Copy Code

If(Page.IsPostBack==true) 
{
//Do whatever you want
}

So I hope you know now what is the postback. So let's discuss now the cross-page posting.

8. What is Generic Class?

Developers like you are familiar with object-oriented programming and understand the benefits it offers. One of the big benefits of object-oriented programming is code re-use, in which you create a base class and inherit it in a derived class. The derived class can simply override virtual methods or add some new methods to customize the behavior of the base class to meet yours need. The Generics is another mechanism offered by the Common Language Runtime (CLR) and programming languages that provide one more form of code re-use and algorithm re-use.

Generics provide a code template for creating type-safe code without referring to specific data types. Generics allow you to realize type safety at compile time. They allow you to create a data structure without committing to a specific data type. When the data structure is used, however, the compiler ensures that the types used with it are consistent for type safety. I want to discuss two benefits of generics, one is type safety and another is performance before explaining with an example.

Type Safety

Generics are mostly used for collections but the framework class library also has non-generic collection classes like ArrayList, Hashtable, SortedList, Stack, Queue. So, first of all, we see an example of a non-generic collection class. In other words, ArrayList where we add integer values to the array list and perform addition operation on the list values.

You need to create a class, ArrayListOperation, and define an Addition method as in the following code snippet.

using System.Collections;
namespace TypeSafety
{
    class ArrayListOperation
    {
        public static int Addition()
        {
            ArrayList list = new ArrayList();
            list.Add(5);
            list.Add(9);
 
            int result = 0;
            foreach (int value in list)
            {
                result += value;
            }
            return result;
        }
    }
}

When you run this code you get a return value from the method.

As you saw in the previous example there is an array list of integer values and get the result as expected but now add one more value to the ArrayList that the data type is float and perform the same Addition operation. Let's see the updated code in the following snippet.

using System.Collections;
namespace TypeSafety
{
    class ArrayListOperation
    {
        public static int Addition()
        {
            ArrayList list = new ArrayList();
            list.Add(5);
            list.Add(9);
            list.Add(5.10);
 
            int result = 0;
            foreach (int value in list)
            {
                result += value;
            }
            return result;
        }
    }
}

In the code above, all three values are easily added to the array list because the ArrayList class Add() method values are an object type, but when retrieving the values using each statement, each value will be assigned an int data type variable. However, this array list has a combination of both integer and float type values and float values won't cast to an int implicitly. That is why the code will give the exception "Specified cast is not valid." That means that an ArrayList is not type safe. This also means that an ArrayList can be assigned a value of any type.

Generics allow you to realize type safety at compile time. They allow you to create a data structure without committing to a specific data type. When the data structure is used, however, the compiler ensures that the types used with it are consistent for type safety. Generics provide type safety, but without any loss of performance or code bloat. The System.Collections.Generics namespace contains the generics collections. Now let's see an example with a generic collection List.

using System.Collections.Generic;
namespace TypeSafety
{
    class ListOperation
    {
        public static int Addition()
        {
            List<int> list = new List<int>();
            list.Add(5);
            list.Add(9);            
 
            int result = 0;
            foreach (int value in list)
            {
                result += value;
            }
            return result;
        }
    }
}</int></int>

9. What is Static Class?

A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself. For example, if you have a static class that is named UtilityClass that has a public method named MethodA, you call the method as shown in the following example:

UtilityClass.MethodA();


A static class can be used as a convenient container for sets of methods that just operate on input parameters and do not have to get or set any internal instance fields. For example, in the .NET Framework Class Library, the static System.Math class contains methods that perform mathematical operations, without any requirement to store or retrieve data that is unique to a particular instance of the Math class. That is, you apply the members of the class by specifying the class name and the method name, as shown in the following example.


double dub = -3.14;
Console.WriteLine(Math.Abs(dub));
Console.WriteLine(Math.Floor(dub));
Console.WriteLine(Math.Round(Math.Abs(dub)));

// Output:
// 3.14
// -4
// 3

As is the case with all class types, the type information for a static class is loaded by the .NET Framework common language runtime (CLR) when the program that references the class is loaded. The program cannot specify exactly when the class is loaded. However, it is guaranteed to be loaded and to have its fields initialized and its static constructor called before the class is referenced for the first time in your program. A static constructor is only called one time, and a static class remains in memory for the lifetime of the application domain in which your program resides.

The following list provides the main features of a static class:

Contains only static members.
Cannot be instantiated.
Is sealed.
Cannot contain Instance Constructors.

Creating a static class is therefore basically the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated. The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.

Static classes are sealed and therefore cannot be inherited. They cannot inherit from any class except Object. Static classes cannot contain an instance constructor; however, they can contain a static constructor. Non-static classes should also define a static constructor if the class contains static members that require non-trivial initialization. For more information, see Static Constructors (C# Programming Guide).

Class:

In a static class, all fields and methods must also be static. This is a useful restriction.

C# program that uses static keyword




using System;

static class Perls
{
    public static int _value = 5;
}

class Program
{
    static void Main()
    {
 Console.WriteLine(++Perls._value);
    }
}

Output

6




10. What is the Difference between Abstraction and Encapsulation?

Abstraction
Encapsulation
1.  Abstraction solves the problem at the design level.
1. Encapsulation solves the problem in the implementation level.
2. Abstraction hides unwanted data and provides relevant data.
2. Encapsulation means hiding the code and data into a single unit to protect the data from the outside world.
3. Abstraction lets you focus on what the object does instead of how it does it
3. Encapsulation means hiding the internal details or mechanics of how an object does something.
4. Abstraction: Outer layout, used in terms of design.
For example: An external of a Mobile Phone, like it has a display screen and keypad buttons to dial a number.
4. Encapsulation- Inner layout, used in terms of implementation.Example: the internal details of a Mobile Phone, how the keypad button and display screen are connected with each other using circuits.

  11.  What is the Difference Between .net framework 4.5 and 4.0 and 3.5?



  12.  What is the difference between Interface and Abstract     Class?

                 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 r implementable
·         Interfaces can be instantiated, but a reference cannot be created

  13. What is constructor?

          Constructor is a special method of a class which will invoke automatically whenever instance or object of class is created. Constructors are responsible for object initialization and memory allocation of its class. If we create any class without constructor, the compiler will automatically create one default constructor for that class. There is always at least one constructor in every class.

Here you need to remember that a class can have any number of constructors and Constructors don’t have any return type, not even void and within a class we can create only one static constructor.


Generally constructor name should be same as class name. If we want to create constructor in a class we need to create a constructor method name same as class name check below sample method for constructor



class SampleA
{
public SampleA()
{
Console.WriteLine("Sample A Test Method");
}
}

14. What is the type of constructor?

Types of Constructors

Basically constructors are 5 types those are

      1.    Default Constructor
      2.    Parameterized Constructor
      3.    Copy Constructor
      4.    Static Constructor
      5.    Private Constructor

Default Constructor

A constructor without having any parameters called default constructor. In this constructor every instance of the class will be initialized without any parameter values like as shown below



using System;
namespace ConsoleApplication3
{
class Sample
{
public string param1, param2;
public Sample()     // Default Constructor
{
param1 = "Welcome";
param2 = "SmartCodeCluster-Senthil";
}
}
class Program
{
static void Main(string[] args)
{
Sample obj=new Sample();   // Once object of class created automatically constructor will be called
Console.WriteLine(obj.param1);
Console.WriteLine(obj.param2);
Console.ReadLine();
}
}
}

When we run above program it will show output like as shown below

Output

Welcome
SmartCodeCluster-Senthil

Parameterized Constructors

A constructor with at least one parameter is called as parameterized constructor. In parameterized constructor we can initialize each instance of the class to different values like as shown below


using System;
namespace ConsoleApplication3
{
class Sample
{
public string param1, param2;
public Sample(string x, string y)     // Declaring Parameterized constructor with Parameters
{
param1 = x;
param2 = y;
}
}
class Program
{
static void Main(string[] args)
{
Sample obj=new Sample("Welcome","SmartCodeCluster-Senthil");   // Parameterized Constructor Called
Console.WriteLine(obj.param1 +" to "+ obj.param2);
Console.ReadLine();
}
}
}
When we run above program it will show output like as shown below

Output


Welcome to SmartCodeCluster-Senthil

Constructor Overloading

In c# we can overload constructor by creating another constructor with same method name and different parameters like as shown below


using System;
namespace ConsoleApplication3
{
class Sample
{
public string param1, param2;

public Sample()     // Default Constructor
{
param1 = "Hi";
param2 = "I am Default Constructor";
}
public Sample(string x, string y)     // Declaring Parameterized constructor with Parameters
{
param1 = x;
param2 = y;
}
}
class Program
{
static void Main(string[] args)
{
Sample obj = new Sample();   // Default Constructor will Called
Sample obj1=new Sample("Welcome","Smartcodecluster-Senthil");   // Parameterized Constructor will Called
Console.WriteLine(obj.param1 + ", "+obj.param2);
Console.WriteLine(obj1.param1 +" to " + obj1.param2);
Console.ReadLine();
}
}
When we run above program it will show output like as shown below

Output


Hi, I am Default Constructor
Welcome to Smartcodecluster-Senthil


Copy Constructor

           A parameterized constructor that contains a parameter of same class type is called as copy constructor. Main purpose of copy constructor is to initialize new instance to the values of an existing instance. Check below example for this


using System;
namespace ConsoleApplication3
{
class Sample
{
public string param1, param2;
public Sample(string x, string y)
{
param1 = x;
param2 = y;
}
public Sample(Sample obj)     // Copy Constructor
{
param1 = obj.param1;
param2 = obj.param2;
}
}
class Program
{
static void Main(string[] args)
{
Sample obj = new Sample("Welcome", " Smartcodecluster-Senthil ");  // Create instance to class Sample
Sample obj1=new Sample(obj); // Here obj details will copied to obj1
Console.WriteLine(obj1.param1 +" to " + obj1.param2);
Console.ReadLine();
}
}
}
When we run above program it will show output like as shown below

Output

Welcome to Smartcodecluster-Senthil
Static Constructor


When we declared constructor as static it will be invoked only once for any number of instances of the class and it’s during the creation of first instance of the class or the first reference to a static member in the class. Static constructor is used to initialize static fields of the class and to write the code that needs to be executed only once.


using System;
namespace ConsoleApplication3
{
class Sample
{
public string param1, param2;
static Sample()
{
Console.WriteLine("Static Constructor");
}
public Sample()
{
param1 = "Sample";
param2 = "Instance Constructor";
}
}
class Program
{
static void Main(string[] args)
{
// Here Both Static and instance constructors are invoked for first instance
Sample obj=new Sample();
Console.WriteLine(obj.param1 + " " + obj.param2);
// Here only instance constructor will be invoked
Sample obj1 = new Sample();
Console.WriteLine(obj1.param1 +" " + obj1.param2);
Console.ReadLine();
}
}
}
When we run above program we will get output like as shown below

Output

Static Constructor
Sample Instance Constructor
Sample Instance Constructor
Importance points of static constructor

-      Static constructor will not accept any parameters because it is automatically called by CLR.
-      Static constructor will not have any access modifiers.
-      Static constructor will execute automatically whenever we create first instance of class
-      Only one static constructor will allowed.

Private Constructor

Private constructor is a special instance constructor used in a class that contains static member only. If a class has one or more private constructor and no public constructor then other classes is not allowed to create instance of this class this mean we can neither create the object of the class nor it can be inherit by other class. The main purpose of creating private constructor is used to restrict the class from being instantiated when it contains every member as static.



using System;
namespace ConsoleApplication3
{
public class Sample
{
public string param1, param2;
public Sample(string a,string b)
{
param1 = a;
param2 = b;
}
private Sample()  // Private Constructor Declaration
{
Console.WriteLine("Private Constructor with no prameters");
}
}
class Program
{
static void Main(string[] args)
{
// Here we don't have chance to create instace for private constructor
Sample obj = new Sample("Welcome","to Smartcodecluster-Senthil ");
Console.WriteLine(obj.param1 +" " + obj.param2);
Console.ReadLine();
}
}
}

Output

Welcome to Smartcodecluster-Senthil


In above method we can create object of class with parameters will work fine. If create object of class without parameters it will not allow us create.


// it will works fine
Sample obj = new Sample("Welcome","to Smartcodecluster-Senthil ");
// it will not work because of inaccessability
Sample obj=new Sample();

Important points of private constructor

-      One use of private construct is when we have only static member.
-      Once we provide a constructor that is either private or public or any, the compiler will not allow us to add public constructor without parameters to the class.
-      If we want to create object of class even if we have private constructors then we need to have public constructor along with private constructor

15. What is the difference between user control and custom control?

Web user controls
Web custom controls
Easier to create
Harder to create
Limited support for consumers who use a visual design tool
Full visual design tool support for consumers
A separate copy of the control is required in each application
Only a single copy of the control is required, in the global assembly cache
Cannot be added to the Toolbox in Visual Studio
Can be added to the Toolbox in Visual Studio
Good for static layout
Good for dynamic layout




16. What are the Web Form Events available in ASP.NET?

Page_Init
Page_Load
Page_PreRender
Page_Unload
Page_Disposed
Page_Error
Page_AbortTransaction
Page_CommitTransaction
Page_DataBinding

17. What is Assembly?

           An assembly exists as a .DLL or .EXE that contains MSIL code that is executed by CLR. An assembly contains interface and classes, it can also contain other resources like bitmaps, files etc. It carries version details which are used by the CLR during execution. Two assemblies of the same name but with different versions can run side-by-side enabling applications that depend on a specific version to use assembly of that version. An assembly is the unit on which permissions are granted. It can be private or global. A private assembly is used only by the application to which it belongs, but the global assembly can be used by any application in the system.

The four parts of an assembly are:

Assembly Manifest - It contains name, version, culture, and information about referenced assemblies.

Type metadata - It contains information about types defined in the assembly.

MSIL - MSIL code.

Resources - Files such as BMP or JPG file or any other files required by application.

18. What is the type of Assembly?

Private Assembly
Static  Assembly 

19. What is the difference between Readonly and Constant and Static?

            Constant and ReadOnly keyword are used to make a field constant which value cannot be modified. Static keyword is used to make members static that can be shared by all the class objects. In this article, I am going to explain the difference among these three.

Constant

Constant fields or local variables must be assigned a value at the time of declaration and after that they cannot be modified. By default constant are static, hence you cannot define a constant type as static.


public const int X = 10;

A const field is a compile-time constant. A constant field or local variable can be initialized with a constant expression which must be fully evaluated at compile time.


void Calculate(int Z)
{
 const int X = 10, X1 = 50;
 const int Y = X + X1; //no error, since its evaluated a compile time
 const int Y1 = X + Z; //gives error, since its evaluated at run time
}

You can apply const keyword to built-in value types (byte, short, int, long, char, float, double, decimal, bool), enum, a string literal, or a reference type which can be assigned with a value null.


const MyClass obj1 = null;//no error, since its evaluated a compile time
const MyClass obj2 = new MyClass();//gives error, since its evaluated at run time
Constants can be marked as public, private, protected, internal, or protected internal access modifiers.

Use the const modifier when you sure that the value a field or local variable would not be changed.

ReadOnly 

           A readonly field can be initialized either at the time of declaration or with in the constructor of same class. Therefore, readonly fields can be used for run-time constants.


class MyClass
{
 readonly int X = 10; // initialized at the time of declaration
 readonly int X1;
 
 public MyClass(int x1)
 {
 X1 = x1; // initialized at run time
 }
}

Explicitly, you can specify a readonly field as static since, like constant by default it is not static. Readonly keyword can be apply to value type and reference type (which initialized by using the new keyword) both. Also, delegate and event could not be readonly. Use the readonly modifier when you want to make a field constant at run time.

Static 

          The static keyword is used to specify a static member, which means static members are common to all the objects and they do not tied to a specific object. This keyword can be used with classes, fields, methods, properties, operators, events, and constructors, but it cannot be used with indexers, destructors, or types other than classes.


class MyClass
{
 static int X = 10;
 int Y = 20;
 public static void Show()
 {
 Console.WriteLine(X);
 Console.WriteLine(Y); //error, since you can access only static members
 }
}

20. What is the difference between ExecuteNonQuery and ExecuteScalar and ExecuteReader?

ExecuteNonQuery

ExecuteNonQuery method will return number of rows effected with INSERT, DELETE or UPDATE operations. This ExecuteNonQuery method will be used only for insert, update and delete, Create, and SET statements. (Read More)

ExecuteScalar

Execute Scalar will return single row single column value i.e. single value, on execution of SQL Query or Stored procedure using command object. It’s very fast to retrieve single values from database. (Read More)

ExecuteReader

Execute Reader will be used to return the set of rows, on execution of SQL Query or Stored procedure using command object. This one is forward only retrieval of records and it is used to read the table values from first to last. (Read More)

21. What is Ajax?

22. What is Dependency?

23. What is Abstract Class?

Abstract class is a class which can’t be instantiate. Class should have “Abstract” key word with the name.  In any one of the method of class having abstract method with in it, then it should be define as abstract class. The class which derived the abstract class should have definition of the abstract method. These classes which derived the abstract class and implement the abstract methods call concrete class.

Abstract class may have the definition of function or may not.  Below is the simple example of an abstract class



public abstract alass AbstractStudent
    {
        String Roll
        {
            get;
            set;
        }

        String FirstName
        {
            get;
            set;
        }
        
        String LastName
        {
            get;
            set;
        }
        

        Public String GetStudentDetails()
             {

                  // Implementation of Method    
             }

        public String SaveStudentDetails ()
            {
                  // Implementation of Method    
             }

        public abstract String CalculateWage();

    }

So, the class having one abstract method so we need to mention the class as "abstract" .

24. When to use abstract Class?

25. What is Interface?

          An interface is a standard or contract that contains only the signatures of methods or events. The implementation is done in the class that inherits from this interface. Interfaces are primarily used to set a common standard or contract.

26. When to use Interface?

I hope everyone is quite familiar with OOP concepts in C++. (Class and Object, Inheritance and its type, so on).


Inheritance allows creating classes that are derived from other classes, so that they automatically include some of its "parent's" members, plus its own. The following are types of inheritances.

Multi-Level Inheritance


class Father
{

    //Father Relations--Members
}
class Mother: Father
{
 
    //Mother Relations--Members
}
class Child: Mother //Multi- Level Inheritance
{

    //Accessing both Relations class members.
}

Multiple Inheritance

class Father
{
    //Father Relations--Members
}
 
class Mother
{
    //Mother Relations--Members
}

class Child: Mother,Father //Multiple Inheritance

{
    //Accessing both Relations class members.
}


This type of multiple inheritance is possible in C++ but it's not possible in C#.

Here, we advised to use "I" as the prefix for the interface to understand that the interface is an interface.
Best example for Interface
Here I have the best example for understanding interfaces.
Not Possible:

1. Open a Console Application and give "InterFaceDemo" as the project name, then add a new class item and rename it "ODDEVEN.CS".


ODDEVEN.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace InterFaceDemo
{
    interface IOne
    {
        void ONE();//Pure Abstract Method Signature
    }
    interface ITwo
    {
        void TWO();
    }
    interface IThree:IOne
    {
        void THREE();
    }
    interface IFour
    {
        void FOUR();
    }
    interface IFive:IThree
    {
        void FIVE();
    }
    interface IEVEN:ITwo,IFour
    {
 
    }
    class ODDEVEN:IEVEN,IFive//Must Implement all the abstract method, in Derived class.
    {
        public void ONE()//Implementation of Abstract Method.
        {
            Console.WriteLine("This is ONE");
        }
        public void TWO()
        {
            Console.WriteLine("This is TWO");
        }
        public void THREE()
        {
            Console.WriteLine("This is THERE");
        }
        public void FOUR()
        {
            Console.WriteLine("This is FOUR");
        }
        public void FIVE()
        {
            Console.WriteLine("This is FIVE");
        }
 
    }
}

Program.cs
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace InterFaceDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This is ODD");
            IFive obj1 = new ODDEVEN();
            obj1.ONE();
            obj1.THREE();
            obj1.FIVE();
 
 
            Console.WriteLine("\n\nThis is EVEN");
            IEVEN obj2 = new ODDEVEN();
            obj2.TWO();
            obj2.FOUR();
 
 
            Console.ReadLine();
        }
    }
}

What is Interface?

 An interface looks like a class, but has no implementation. The only thing it contains are declarations of events, indexers, methods and/or properties. The reason interfaces only provide declarations is because they are inherited by structs and classes, that must provide an implementation for each interface member declared.

 So, what are interfaces good for if they don't implement functionality? They're great for putting together plug-n-play like architectures where components can be interchanged at will.

Since all interchangeable components implement the same interface, they can be used without any extra programming. The interface forces each component to expose specific public members that will be used in a certain way. Because interfaces must be implemented by derived structs and classes, they define a contract.


interface IMyInterface
{
            void MethodToImplement();//Abstract Method signature.
}

class InterfaceImplementer : IMyInterface
{
         static void Main()
         {
                     InterfaceImplementer  obj = new InterfaceImplementer();
                     obj.MethodToImplement();
         }

         public void MethodToImplement()
         {
                //Abstract Method Implementation
         }
}



27. What is the HTTPHandler?

          HttpHandler is the low level Request and Respone API to service incoming Http requests. All handlers implement the IHttpHandler Interface. There is no need to use any extra namespace to use it as it contains in the System.Web namespace. Handlers are somewhat analogous to Internet Server Application Programming Interface (ISAPI) extensions.

Each incoming HTTP request received by ASP.NET is ultimately processed by a specific instance of a class that implements IHTTPHandler. IHttpHandlerFactory provides the infrastructure that handles the actural resolution of URL requests to IHttpHandler instances. In addition to the default IHttpHandlerFactory classes provided by ASP.Net. Developers can optionally create and register factories to support rich request resolution.

28. What are the types of exception?

29. What is the ArrayList?

The following is the output:

            It represents an ordered collection of an object that can be indexed individually. It is basically an alternative to array. However, unlike array can add and remove items from a list at a specified position using an index and the array resizes itself automatically. It also allows dynamic memory allocation. Adding, searching and sorting items in the list

1.        30. What is the difference between Array and ArrayList?


Array
ArrayList
These are strong type collection and allow to store fixed length
Array Lists are not strong type collection and size will increase or decrease dynamically
In arrays we can store only one datatype either int, string, char etc….
In arraylist we can store all the datatype values
Array belongs to System.Array namespace
ArrayList belongs to System.Collection namespace

31. What is the difference between Datatable and Hashtable?

32. What is dependency Injection?

            ASP.NET MVC framework itself creates controller objects at run time. There is only one prerequisite that is controller class must have a parameter less constructor. But if you need to pass objects a constructor parameters and for that reason if you create parameterized constructor then what will happen? Simply framework will fail to create those controllers object that have parameterized constructor. In that case we need to create controller objects by our self and inject controller parameters there.

There are many ways you can inject dependency to a class, For example.

Setter property
Method
Constructor.

In this article I explain with code sample how to inject controller dependency to ASP.NET MVC framework using constructor. Without creating custom controller factory, inject dependency to controllers are not possible. So I also explain how to create a very simple custom controller factory and register it to ASP.NET MVC framework. I also demonstrate a way to inject dependency to controllers using Managed Extensible Framework (MEF)

33. What are differences between system.stringbuilder and system.string?

The main difference is system.string is immutable and system.stringbuilder is a mutable. Append keyword is used in string builder but not in system.string.

Immutable means once we created we cannot modified. Suppose if we want give new value to old value simply it will discarded the old value and it will create new instance in memory to hold the new value.

34. What is boxing and unboxing?

Boxing is a process of converting value type into reference type.
Unboxing is a process of converting reference type to value type.

35. What is Mutable and Immutable?

Immutable means that once initialized, the state of an object cannot change.

Mutable Objects: When you have a reference to an instance of an object, the contents of that instance can be altered

For example - strings in .NET are immutable. Whenever you do an operation on a string (trims, upper casing, etc...) a new string gets created.

Immutable Objects: When you have a reference to an instance of an object, the contents of that instance cannot be altered

In practice, if you want to create an immutable type, you only allow getters on it and do not allow any state changes (so any private field cannot change once the constructor finished running).

36. What are the differences between Application object and session object?

The session object is used to maintain the session of each user. If one user enter in to the application then they get session id if he leaves from the application then the session id is deleted. If they again enter in to the application they get different session id.
But for application object the id is maintained for whole application.

37. What is the difference Grid View and between Data Grid (Windows)?

Ans:

1) GridView Control Enables you to add sorting, paging and editing capabilities without writing any code. 
2) GridView Control Automatically Supports paging by setting the ‘PagerSetting’ Property.The Page Setting Property supports four Modles 

a. Numeric(by default) 
b. Next Previous 
c. NumericFirstLast 
d. Next PreviousLast 

3) It is Used in asp.net 
4) GridView Supports RowUpdating and RowUpdated Events. 
5) GidView is Capable of Pre-Operations and Post-Operations. 
6) GridView Has EditTemplates for this control 
7) It has AutoFormat 

DataGrid(Windows) 

1) DataGid Control raises single Event for operations 
2) DataGird Supports the SortCommand Events that occur when a column is Soted. 
3) DataGrid Supports UpdataCommand Event that occurs when the UpdateButton is clicked for an item in the grid. 
4) DataGrid is used in Windows GUI Application. 
5) It doesnot have EditTemplates for this control 
6) It doesnot have AutoFormat

38. What is Garbage Collection?

39. What are the types of session Management?

40. What is Serialization and deserialization?

Serialization is the process of converting an object into a stream of bytes.
Deserialization is the process of creating an object from a stream of bytes.

41. What is the difference between structure and Class?

o Structures are value type while Classes are reference type.
o Structures cannot have constructor or destructors while Classes can have them.
o Structures do not support Inheritance while Classes do support Inheritance.

42. Differentiate globalization and localization.

"Globalization is the process of designing and developing a software product that functions in multiple cultures/locales."

"Localization is the process of adapting a globalized application, which you have already processed for localizability, to a particular culture/locale."

43. What is the difference between ‘Web.config’ and ‘Machine.config’?

             Web.config files are used to apply configuration settings to a particular web application whereas machine.config file is used to apply configuration settings for all the websites on a web server.

Web.config files are located in the application's root directory or inside a folder situated in a lower hierarchy. The machine.config is located in the Windows directory Microsoft.Net\Framework\Version\CONFIG.

There can be multiple web.config files in an application nested at different hierarchies. However there can be only one machine.config file on a web server.

44. Difference between Response.Redirect and Server.Transfer?

           In case of Response.Redirect, a new request is generated from client-side for redirected page. It's a kind of additional round trip. As new request is generated from client, so the new URL is visible to user in browser after redirection.

While in case of Server.Transfer, a request is transferred from one page to another without making a round trip from client. For the end user, URL remains the same in browser even after transferring to another page.

45. What is Dataset?

             DataSet is an in memory representation of a collection of Database objects including tables of a relational database schemas. DataSet is always a bulky object that reuqires a lot of memory space compare to DataReader. We can say that the DataSet is a small database because it stores it stores the schema and data in the application memory area. DataSet fetches all data from the datasource at a time to its memory area. So we can traverse through the object to get the required data like querying database.

46. What is DataReader?

            DataReaderis like a forward only recordset. It fetches one row at a time so very less network compare to DataSet(Fethces all the rows at a time). DataReader is readonly so we can't do any transaction on them. DataReader will be the best choice where we need to show the data to the user which requires no transaction. As DataReader is forward only so we can't fetch data randomly. .Net Data Providers optimizes the datareader to handle huge amount of data.

47. What are the types of validation controller in ASP.NET?

In order to validate user input, ASP.NET provides validation server controls. All validation controls inherits from BaseValidator class which contains the common validation properties and methods like ControlToValidate, Enabled, IsValid, EnableClientScript, ValidationGroup,Validate() etc.

ASP.NET provides a range of validation controls:

RequiredFieldValidator validates compulsory/required input.
RangeValidator validates the range. Validates that input falls between the given range values.
CompareValidator validates or compares the input of a control with another control value or with a fixed value.
RegularExpressionValidator validates input value against a defined regular expression pattern.
CustomValidator allows to customize the validation logic with respect to our application logic.
ValidationSummary displays all errors on page collectively.

48. What are the types of Authentication mode in asp.net?

There are three types of authentication available in ASP.NET:

Windows Authentication: This authentication method uses built-in windows security features to authenticate user.
Forms Authentication: authenticate against a customized list of users or users in a database.
Passport Authentication: validates against Microsoft Passport service which is basically a centralized authentication service.

49. What is the difference between ToString () and Convert.ToString()?

50. Describe how Passport authentication works.

ASP.NET application with Passport authentication implemented checks the user’s machine for a current passport authentication cookie. If it is not available, ASP.NET directs the user to a Passport sign-on page. The Passport service authenticates the user, stores an authentication cookie on the user’s computer and direct the user to the requested page.  

51. What is JavaScript?

JavaScript is a cross-platform, object-oriented scripting language. It is a small and lightweight language. Inside a host environment, JavaScript can be connected to the objects of its environment to provide programmatic control over them

JavaScript contains a standard library of objects, such as Array, Date and Math, and a core set of language elements such as operators, control structures, and statements, Core JavaScript can be extended for a variety of purposes by supplementing it with additional objects; for example

Client-side JavaScript extends the core language by supplying objects to control a browser and it’s Document Object Model (DOM). For example, Client-side extensions allow an application to place elements on an HTML form and respond to user events such as mouse clicks, form input, and page navigation.
Server-side JavaScript extends the core language by supplying objects relevant to running JavaScript on a server, For example, server-side extensions allow an application to communicate with a database, provide continuity of information from one invocation to another of the application, or perform file manipulations on a server.

52. What is Jquery?

53. What is the difference between Javascript and Jquery?

54. What is the difference between XML and JSON?


JSON
XML
Stands For
JSON: “JavaScript Object Notation”.
XML “Extensible Markup Lnaguage”.
Extended From
JSON is extended from JavaScript
XML is extended from SGML: “Standard Generalized Markup Language”.
Purpose
JSON is one type of text-based format or standard for interchanging data i.e. Human readable. JSON is developed by “Douglas Crockford”.
XML is a Markup Language having format that contains set of rules for the encoding the documents which is readable for both human & machine.XML is developed by W3C: “World Wide Web Consortium”.
Syntax
JSON syntax is lighter then XML as JSON has serialized format of data having less redundancy. JSON does not contain start and end tags.
XML is not so lighter as JSON as having start and end tags and it takes more character than JSON to represent same data.
Speed
JSON is light-weighted in compare to XML as it has serialized format and so faster also.
XML is not so light weighted as JSON
Support of Data Type & Array
JSON support datatype including integer and strings. JSON also supports array.
XML does not provide any data type so needs to be parsed into particular datatype. No direct support for array also.
Object Support
JSON has support of native objects
XML can get support of objects through mixed use of attributes & elements
Comments
JSON does not support Comments
XML support comments
Namespace
JSON does not have support for Namespaces.
XML support Namespace
Mapping
JSON is data oriented and can be mapped more easily
XML is document oriented and needs more effort for mapping.
Parsing
JSON uses only evel() for parsing  i.e. for interpreting the JavaScript code & returns the result. It does not need any additional code for parsing.
XML needs XML Document Object Model(DOM) implementation & with that additional code for mapping text back to the JavaScript objects.
Application
For Web services, JSON is better
For configuration. XML is better.

55. What are difference between GET and POST Methods?

GET Method ():

1) Data is appended to the URL. 
2) Data is not secret. 
3) It is a single call system 
4) Maximum data that can be sent is 256. 
5) Data transmission is faster 
6) this is the default method for many browsers

POST Method ():

1) Data is not appended to the URL. 
2) Data is Secret 
3) it is a two call system. 
4) There is no Limit on the amount of data. That is characters any amount of data can be sent. 
5) Data transmission is comparatively slow. 
6) No default and should be explicitly specified.

56. What is selector in Jquery?

57. What is bootstrap?

Responsive:

1 There is a multitude of different screen sizes across phones, “phablets”, tablets, desktops, game consoles, TVs, even wearables. Screen sizes will always be changing, so it’s important that your site can adapt to any screen size, today or in the future. 
Set the viewport

Pages optimized for a variety of devices must include a meta viewport element in the head of the document. A meta viewport tag gives the browser instructions on how to control the page's dimensions and scaling.