Академический Документы
Профессиональный Документы
Культура Документы
1.What is class?
Class is a blue print, it contains data and behavior of a type. Let me take an example that,
consider a vehicle as a class, it can have type, color, price like data and calculate speed as
behavior of the class.
2.What is object?
Object is an instance of a class, and basically is a block of memory that has been allocated and
configured according to the blueprint(class).
3.What is Inheritance?
Inheritance is one of the main attribute in object-oriented language. It allows us to create a new
class which can reuse, extends or modifies behavior of parent class. The class whose behaviors
been inherited is called base class, and the class inherits the members of the base class is
derived class. For example: we have a vehicle class and a car class. Car class can be derived
from vehicle class to inherit all data and behaviors of base class.
Coming to compile time polymorphism, more than one method can have same name with
different parameters in terms of type of parameters and number of parameters, doesn’t make
any difference with return type. For example, in data access layer we can write several methods
with same name to get any table data.
But run time polymorphism, derived class can have a method implementation which have same
method name in its base class. So, we can add override the method in base class by adding
virtual key word to base class method, and override keyword to derived class method. So, we
will be able to customize our own functionality in derived class function.
Encapsulation: It is a strategy used as part of abstraction; and it refers to the state of the
objects- objects encapsulate their state and hide it from the outside; outside users of the class
interact with it through its methods. Here we provide getter and setter methods to access them.
we achieve encapsulation at implementation level though access specifiers like public, private
and protected.
Coupling: A measure of how much a module (package, class, method) relies on other
modules. It is desirable to reduce coupling, or reduce the amount that a given module relies
on the other modules of a system.
Single responsibility: This principle states that every module/class should have single
responsibility.
Open Closed principle: The module code opens for extension and closed for modification.
Liskov Substitution Principle: LSP states that Parent object should be able to easily
replace Child Object without altering any of desirable properties of Parent class
Interface Segregation Principle: ISP states that no client should be forced to implement the
methods that are not used by it.
Dependency inversion principle: High level modules should not depend on low level
modules but should depend on abstraction.
C#
C# value types further divides into simple types, enum types, struct types, and nullable
value types.
C# reference types further divides into class types, interface types, array types, delegate
types.
Out keyword is also like ref keyword, but the variable should be initialized in calling
method. And useful for returning more than two values.
d/f
ref tells the compiler that the object is initialized before entering the function,
while out tells the compiler that the object will be initialized inside the function.
19. What are checked and unchecked keywords in C#?
In checked context arithmetic overflow rises an exception and in unchecked context
arithmetic overflow is ignored and the result is truncated.
Structures instantiated with new operator supports constructors moreover doesn’t support
inheritance, and destructors.
Where as collections unlike arrays can manage group of objects that can grow and shrink
dynamically according to application needs. And for some collections we can insert key
value pairs.
There are two different types of collections: Generics and non-generics
Non-generic types can grow and shrink dynamically and accepts any types in the
collections. So, it actually accepts Object type to store. When we need to add any type,
that type will be boxed to Object type. We have collections like: ArrayList, SortedList,
HashTable, Stack and Queue.
Where as generic types are type safe and dynamically grows and shrinks. They are List,
SortedList, Dictionary, stack and queue.
For example, take method compare methods which takes two int arguments, later we
needed to compare strings. Generics helps here to not to write another method.
By using threads, we can get several benefits like concurrency and effective CPU
utilization.
Multithreading very useful for distributed and scalable server-side applications as each
thread can hold each user request so that no user waits until other users gets the response.
In C# we can achieve this using thread pools.
Thread pool is a pool of threads waits of the requests and handles the request and once
request has get done the same thread can be used by other requests.
.NET
The code, which is developed in .NET framework, is known as managed code. This code
is directly executed by CLR with help of managed code execution. Any language that is
written in .NET Framework is managed code.
Managed code uses CLR which in turns looks after your applications by managing
memory, handling security, allowing cross - language debugging, and so on.
Applications that do not run under the control of the CLR are said to be unmanaged, and
certain languages such as C++ can be used to write such applications, which, for
example, access low - level functions of the operating system. Background compatibility
with code of VB, ASP and COM are examples of unmanaged code.
In the common language runtime (CLR), the garbage collector serves as an automatic
memory manager. It provides the following benefits:
The heap is organized into generations, so it can handle long-lived and short-lived
objects. Garbage collection primarily occurs with the reclamation of short-lived objects
that typically occupy only a small part of the heap. There are three generations of objects
on the heap:
Newly allocated objects form a new generation of objects and are implicitly
generation 0 collections, unless they are large objects, in which case they go on the
large object heap in a generation 2 collection.
Most objects are reclaimed for garbage collection in generation 0 and do not survive
to the next generation.
ADO .NET
46. What are main benefits of ADO.NET?
Following are the benefits of ADO.Net:
Programmability
Maintainability
Interoperability
Performance
Scalability
ExecuteNonQuery
Executes the command defined in the CommandText property against the connection
defined in the Connection property for a query that does not return any row (an
UPDATE, DELETE, or INSERT). Returns an Integer indicating the number of rows
affected by the query.
ExecuteReader
Executes the command defined in the CommandText property against the connection
defined in the Connection property. Returns a "reader" object that is connected to the
resulting row set within the database, allowing the rows to be retrieved.
ExecuteScalar
Executes the command defined in the CommandText property against the connection
defined in the Connection property. Returns only a single value (effectively the first
column of the first row of the resulting row set, any other returned columns and rows
are discarded). It is fast and efficient when only a "singleton" value is required.
SQL
52. Types of Indexing in SQL Server?
An index is an on-disk structure associated with a table or view that speeds retrieval of
rows from the table or view. An index contains keys built from one or more columns in
the table or view. These keys are stored in a structure (B-tree) that enables SQL Server to
find the row or rows associated with the key values quickly and efficiently.
Clustered:
o Clustered indexes sort and store the data rows in the table or view based on their key
values. These are the columns included in the index definition. There can be only one
clustered index per table, because the data rows themselves can be sorted in only one
order.
o The only time the data rows in a table are stored in sorted order is when the table
contains a clustered index. When a table has a clustered index, the table is called a
clustered table. If a table has no clustered index, its data rows are stored in an
unordered structure called a heap.
Nonclustered:
o Nonclustered indexes have a structure separate from the data rows. A nonclustered
index contains the nonclustered index key values and each key value entry has a
pointer to the data row that contains the key value.
o The pointer from an index row in a nonclustered index to a data row is called a row
locator. The structure of the row locator depends on whether the data pages are stored
in a heap or a clustered table. For a heap, a row locator is a pointer to the row. For a
clustered table, the row locator is the clustered index key.
When primary key is created for a table, data base engine automatically enforces data
uniqueness by creating unique index for the primary key columns. So that we cannot
have duplicated values for primary key column or columns. As well as we cannot have
null values in primary key values.
Foreign Key: A foreign key (FK) is a column or combination of columns that is used to
establish and enforce a link between the data in two tables to control the data that can be
stored in the foreign key table. In a foreign key reference, a link is created between two
tables when the column or columns that hold the primary key value for one table are
referenced by the column or columns in another table. This column becomes a foreign
key in the second table. Foreign key columns frequently used in join criteria of both
tables.
Indexed views
Partitioned views
System views
ASP.NET
At each stage of the page life cycle, the page raises some events, which could be coded.
An event handler is basically a function or subroutine, bound to the event, using declarative
attributes such as Onclick or handle.
Following are the page life cycle events:
PreInit - PreInit is the first event in page life cycle. It checks the IsPostBack property
and determines whether the page is a postback. It sets the themes and master pages,
creates dynamic controls, and gets and sets profile property values. This event can be
handled by overloading the OnPreInit method or creating a Page_PreInit handler.
Init - Init event initializes the control property and the control tree is built. This event
can be handled by overloading the OnInit method or creating a Page_Init handler.
InitComplete - InitComplete event allows tracking of view state. All the controls turn
on view-state tracking.
LoadViewState - LoadViewState event allows loading view state information into the
controls.
LoadPostData - During this phase, the contents of all the input fields are defined with
the <form> tag are processed.
PreLoad - PreLoad occurs before the post back data is loaded in the controls. This
event can be handled by overloading the OnPreLoad method or creating a
Page_PreLoad handler.
Load - The Load event is raised for the page first and then recursively for all child
controls. The controls in the control tree are created. This event can be handled by
overloading the OnLoad method or creating a Page_Load handler.
LoadComplete - The loading process is completed, control event handlers are run, and
page validation takes place. This event can be handled by overloading the
OnLoadComplete method or creating a Page_LoadComplete handler
PreRender - The PreRender event occurs just before the output is rendered. By
handling this event, pages and controls can perform any updates before the output is
rendered.
PreRenderComplete - As the PreRender event is recursively fired for all child
controls, this event ensures the completion of the pre-rendering phase.
SaveStateComplete - State of control on the page is saved. Personalization, control
state and view state information is saved. The HTML markup is generated. This stage
can be handled by overriding the Render method or creating a Page_Render handler.
UnLoad - The UnLoad phase is the last phase of the page life cycle. It raises the
UnLoad event for all controls recursively and lastly for the page itself. Final cleanup is
done and all resources and references, such as database connections, are freed. This
event can be handled by modifying the OnUnLoad method or creating a Page_UnLoad
handler.
In the below diagram, when first request is made from client to server for a web page (say
a simple registration form), IsPostback property value will be false. It will be
a GET request that may be initiated by:
After user filled the returned form and presses a button (say submit button, or use
JavaScript to submit form), an HTTP Post request is made to server on same page with
data as shown in point 3. This time IsPostbackproperty value will be true. Server
processes the request and returns a response back to client.
Another concept related to this approach is "Callback" that is also asked sometimes
during a technical interview question. Click here to understand Postback Vs Callback in
ASP.NET.
62. Explain about ASP.NET MVC Page Life Cycle?
It is the sequence of events that happen every time an HTTP request is handled by our
application.
The entry point for every MVC application begins with routing. After the ASP.NET
platform has received a request, it figures out how it should be handled through the URL
Routing Module.
Modules are .NET components that can hook into the application life cycle and add
functionality. The routing module is responsible for matching the incoming URL to routes
that we define in our application.
All routes have an associated route handler with them and this is the entry point to the
MVC framework.
The MVC framework handles converting the route data into a concrete controller that can
handle requests. After the controller has been created, the next major step is Action
Execution. A component called the action invoker finds and selects an appropriate Action
method to invoke the controller.
After our action result has been prepared, the next stage triggers, which is Result
Execution. MVC separates declaring the result from executing the result. If the result is a
view type, the View Engine will be called and it's responsible for finding and rending our
view.
If the result is not a view, the action result will execute on its own. This Result Execution
is what generates an actual response to the original HTTP request.
ASP.NET Web Forms uses Page controller pattern approach for rendering layout,
whereas ASP.NET MVC uses Front controller approach. In case of Page controller
approach, every page has its own controller, i.e., code-behind file that processes the
request. On the other hand, in ASP.NET MVC, a common controller for all pages
processes the requests.
ASP.NET validation controls define an important role in validating the user input data.
Whenever the user gives the input, it must always be validated before sending it across to
various layers of an application. If we get the user input with validation, then chances are
that we are sending the wrong data. So, validation is a good idea to do whenever we are
taking input from the user.
There are the following two types of validation in ASP.NET:
Client-Side Validation
Server-Side Validation
Client-Side Validation:
When validation is done on the client browser, then it is known as Client-Side Validation.
We use JavaScript to do the Client-Side Validation.
Server-Side Validation:
When validation occurs on the server, then it is known as Server-Side Validation. Server-
Side Validation is a secure form of validation. The main advantage of Server-Side
Validation is if the user somehow bypasses the Client-Side Validation, we can still catch
the problem on server-side.
RequiredFieldValidator Control
CompareValidator Control
RangeValidator Control
RegularExpressionValidator Control
CustomFieldValidator Control
ValidationSummary
Types of Filters:
Action Filters: Action filters are used to implement logic that gets executed before
and after a controller action executes.
Authorization Filters: Authorization filters are used to implement authentication and
authorization for controller actions.
Result Filters: Result filters contain logic that is executed before and after a view
result is executed. For example, you might want to modify a view result right before
the view is rendered to the browser.
Exception Filters: Exception filters are the last type of filter to run. You can use an
exception filter to handle errors raised by either your controller actions or controller
action results. You can also use exception filters to log errors.
Action filters are one of most commonly used filters to perform additional data
processing or manipulating the return values or cancelling the execution of action or
modifying the view structure at run time.
Action Filters are additional attributes that can be applied to either a controller section or
the entire controller to modify the way in which action is executed. These attributes are
special .NET classes derived from System.Attribute which can be attached to classes,
methods, properties and fields.
Output Cache: This action filter caches the output of a controller action for a
specified amount of time.
Handle Error: This action filter handles errors raised when a controller action
executes.
Authorize: This action filter enables you to restrict access to a particular user or role.
Routing is a mechanism to process the incoming url that is more descriptive and give
desired response. In this case, URL is not mapped to specific files or folder as was the
case of earlier days web sites.
There are two types of routing (after the introduction of ASP.NET MVC 5).
1. Convention based routing: to define this type of routing, we call MapRoute method
and set its unique name, URL pattern and specify some default values.
2. Attribute based routing: to define this type of routing, we specify the Route attribute
in the action method of the controller.
Routing is the URL pattern that is mapped together to a handler. Routing is responsible
for incoming browser request for particular MVC controller. In other ways let us say
routing help you to define a URL structure and map the URL with controller. There are
three segments for routing that are important,
1. Controller Name
2. ActionMethod Name
3. Parameter
74. Difference between view and Partial view?
View:
It contains the layout page.
Before any view is rendered, viewstart page is rendered.
View might have markup tags like body, html, head, title, meta etc.
View is not lightweight as compare to Partial View.
Partial View:
It does not contain the layout page.
Partial view does not verify for a viewstart.cshtml.We cannot put common code for a
partial view within the viewStart.cshtml.page.
Partial view is designed specially to render within the view and just because of that it
does not consist any mark up.
We can pass a regular view to the RenderPartial method.
75. What is view engine, razor views and explain advantages of Razor engine?
The view engine is responsible for creating HTML from your views. Views are usually
some kind of mix up of HTML and a programming language.
Razor is an ASP.NET programming syntax used to create dynamic web pages with
the C# or Visual Basic .NET programming languages. The Razor syntax is a template
markup syntax, based on the C# programming language, that enables the programmer to
use an HTML construction workflow.
For example, ASP.NET comes with its own view engine out of the box. That is the one
where views have lots of tags like <% %> and <%: %>. It uses the .aspx file extension.
With ASP.NET MVC3, another out-of-the-box view engine was added, Razor, which has
a more appealing syntax, e.g. <div>@Model.UserName</div>.